Most website software, including WordPress, keeps its content in a MySQL database. This guide shows how to create a database and a user, connect your site and look after the database.
In this guide
Create a database
- In cPanel, open MySQL Databases.
- Under Create New Database, enter a short name and select Create Database. cPanel adds your username to the front, such as
username_shop.
Create a user and give it access
- Under MySQL Users, enter a username and a strong password, and select Create User. Keep a copy of the password.
- Under Add User to Database, choose the user and the database and select Add.
- Tick All Privileges and select Make Changes.
Connect your website
Your site needs four details: the database name, the user, the password and the host. The host is localhost. For WordPress, they go in wp-config.php:
define('DB_NAME', 'username_shop');
define('DB_USER', 'username_shopuser');
define('DB_PASSWORD', 'your-password');
define('DB_HOST', 'localhost');
Use phpMyAdmin
Open phpMyAdmin in cPanel to browse tables, run queries, and import or export a database.
- Export: choose the database, select Export, keep the Quick method and SQL format, and select Export.
- Import: choose the database, select Import, choose your
.sqlfile and select Import.
Look after your database
- Export a copy before big changes, and keep regular backups. See How to back up and restore your WordPress site.
- In phpMyAdmin, select the tables and choose Check table, Repair table or Optimize table when something looks wrong.
- Remove data you no longer need, such as old revisions and logs, to keep the database small.
If something goes wrong
- Can't connect. Check the name, user and password, and that the user is added to the database with all privileges.
- Import file too large. Compress it as a
.zipor.gzfile, or split it into parts. Open a ticket if it still won't fit. - Crashed table. Use Repair table in phpMyAdmin.
- Slow site. Large tables without indexes slow pages down. Clean up old data, and ask your developer to check slow queries.
Related guides
- How to install WordPress on GHost Cloud
- WordPress troubleshooting: common errors and fixes
- cPanel overview: a beginner's guide
- How to manage files with cPanel File Manager
Stuck? Open a ticket and a person will reply.
