Help center · Domains and cPanel
MySQL databases in cPanel: create, permissions, import, and export
To create a MySQL database in cPanel, open MySQL Databases, type a name, and click Create Database. Then create a user with a password, add that user to the database, and check ALL PRIVILEGES. The database only works when all three things exist: the database, the user, and the link between the two.
A database stores the information behind your website: in WordPress, that means posts, pages, users, and settings. This article shows how to create everything in cPanel, how to import and export with phpMyAdmin, where to put the details in wp-config.php, and which errors appear most often. Menu names change depending on the cPanel version, so use the paths below as a reference.
Before you start
- Installing a new WordPress site? The cPanel installer or Softaculous creates the database for you. See how to install WordPress in cPanel. This step-by-step is for when you need to create the database manually, for example when migrating a site.
- Write down three details: database name, user name, and password. You’ll need them for your site. Use a long password and store it in a password manager, as suggested in the article Website passwords and access.
Option 1: create with the MySQL Database Wizard
The wizard walks you through every step in sequence and is the safest route for beginners.
- Log in to cPanel and, in the Databases section, open MySQL® Database Wizard.
- In step 1, type the database name, such as
site, and click Next Step. - In step 2, type the user name and password (use the cPanel password generator if you prefer) and click Create User.
- In step 3, check ALL PRIVILEGES and click Next Step.
- Done: cPanel shows a confirmation message. The database is ready to use.
Option 2: create in MySQL Databases
This gives the same result, across separate screens. It’s useful when you already have a user and only want to create another database, or the other way around.
- Open MySQL Databases.
- Under Create New Database, type the name and click Create Database.
- Further down, under MySQL Users, create the user with a password.
- Under Add User To Database, choose the user and the database and click Add.
- On the privileges screen, check ALL PRIVILEGES and save.
The prefix for users and databases
cPanel automatically adds your account name in front of the database and user names. If your account is called myaccount and you create the database site, the real name will be myaccount_site. The same goes for the user.
This is the most common mistake people make when setting up a site: typing site in wp-config.php instead of myaccount_site. The full name appears in the database and user lists in cPanel, and that’s the one you must copy. There is also a length limit for user names, so prefer short names. If cPanel rejects the name, shorten it.
What each permission does
| Privilege | What it’s for |
|---|---|
| ALL PRIVILEGES | Read, write, create, and delete tables. This is what WordPress needs. |
| Read-only (SELECT) | Query data. Useful for reports, not for the website. |
| No link to the database | The user exists but can’t connect. The site shows a connection error. |
For a WordPress site, check ALL PRIVILEGES and use a dedicated user for each database. That way, if a password leaks, the damage is limited to one site.
Where to use the details in wp-config.php
The wp-config.php file sits in your site’s folder (usually public_html) and stores the connection to the database. Open it from the File Manager and check these lines:
define( 'DB_NAME', 'myaccount_site' );
define( 'DB_USER', 'myaccount_user' );
define( 'DB_PASSWORD', 'your-password-here' );
define( 'DB_HOST', 'localhost' );
- DB_NAME: the full database name, with the prefix.
- DB_USER: the full user name, with the prefix.
- DB_PASSWORD: the user’s password, without extra spaces at the beginning or end.
- DB_HOST: on cPanel hosting the value is usually
localhost. If your site was migrated from somewhere else, replace it with the value support indicates, if it’s different.
If any of these details is wrong, WordPress shows “Error establishing a database connection.” The article Error establishing a database connection in WordPress explains how to diagnose it.
Export the database with phpMyAdmin
Make an export before any major change, such as updating plugins or switching themes.
- In cPanel, open phpMyAdmin.
- In the left column, click the database name.
- Click the Export tab.
- Leave the method on Quick and the format on SQL.
- Click Export (or Go, depending on the version). Your browser downloads a
.sqlfile.
Store the file somewhere safe. It doesn’t replace a full backup: for that, see backing up in cPanel with JetBackup.
Import a database with phpMyAdmin
- Create the database, the user, and the link between them, as described above.
- Open phpMyAdmin and click the empty database name in the left column.
- Click the Import tab.
- Under Choose File, select the
.sqlfile (or.sql.zip, if your phpMyAdmin accepts it). - Leave the character set on utf-8 and click Import.
- Wait for the success message and check that the tables appear in the list.
Always import into an empty database. If the database already has tables with the same names, the import fails or mixes data.
Common errors and how to fix them
- Connection error on the site. Check the prefix, user, password, and
DB_HOSTinwp-config.php. Also check that the user was added to the database with privileges. This is the most frequent cause. - Import interrupted or file too large. phpMyAdmin respects PHP’s upload and time limits, and large files can exceed them. See the article on the upload_max_filesize limit in WordPress, which explains how to adjust the limit. If it still doesn’t work, split the file into smaller parts or ask support through contact.
- “Access denied for user”. The password is wrong or the user isn’t linked to the database. Reset the password under MySQL Databases and update
wp-config.php. - “Table already exists” during import. The database wasn’t empty. Delete the old tables (after exporting a copy) and import again.
- Strange characters after importing. The file’s character encoding wasn’t utf-8. Export again from the source using utf-8 or choose the correct encoding during import.
Frequently asked questions
Can I use the same user for several databases?
You can, but it’s not recommended. One user per site limits the damage if a password leaks.
I lost the password for the database user. What now?
You can’t view the current password. Under MySQL Databases, in the users section, change the password and update DB_PASSWORD in wp-config.php.
Is there a limit on the number of databases in my plan?
That depends on the plan you have. Check in cPanel or ask support through contact.
Does deleting the database delete the site?
It deletes the WordPress content: posts, pages, and settings. The files stay in the folder, but the site stops working. Export a copy before deleting anything.
How do I restore a database I deleted by mistake?
MigraCloud uses JetBackup to make automatic backups, and you restore them yourself in cPanel. See the step-by-step guide in backing up in cPanel with JetBackup. For backup timeframes and retention, ask support.