Create a MySQL Database and User, and Use phpMyAdmin

Updated: 4 December 20264 min read33 viewsMarkdown

WordPress, e-commerce software and most PHP applications store their data in a MySQL (or compatible MariaDB) database. Getting a working database in cPanel takes three steps: create the database, create a user, and link the user to the database with privileges.

Database cylinder, user card with privileges and a table view
Database + user + privileges = a working connection.

Before you start

  • Log in to cPanel. You can see your plan's database limit in the statistics panel on the cPanel home page.
  • Be ready to set a strong password, and note it down: you will enter it in your application's config file.

Create the database, user and privileges

The quickest route is Database Wizard in the Databases section. The same steps also work on the MySQL Databases page.

  1. Create the database. Type a short name (for example site) under Create New Database and click Create Database. cPanel adds your account prefix: username_site.
  2. Create the user. Under MySQL Users, enter a username and password. Password Generator creates a strong one. The username also gets the prefix: username_siteuser.
  3. Add the user to the database. Under Add User To Database, pick the user and database and click Add. Tick ALL PRIVILEGES and save with Make Changes.
Three steps: database form, user form, all privileges ticked
1: Create the database, 2: create the user, 3: grant all privileges.
Common mistake

Creating the user but forgetting to add it to the database is the number one cause of "Access denied" errors. Do not skip step three.

Enter the details in your application

Use these four values in your application's config file (wp-config.php for WordPress):

Database name : username_site
Username      : username_siteuser
Password      : (the password you set)
Host          : localhost

Because the site and the database live on the same hosting account, the host is localhost.

Using phpMyAdmin

phpMyAdmin lets you manage your database in the browser. Click Databases > phpMyAdmin in cPanel and it opens without asking for another password.

Export (backup)

  1. Select the database in the left-hand list.
  2. Open the Export tab and keep Quick as the method and SQL as the format.
  3. Click Go; a .sql file downloads to your computer.

Import (migration or restore)

  1. Select the target database. If it is not empty, check which tables will be overwritten.
  2. On the Import tab, choose your .sql or .sql.gz file and click Import (or Go).
Note

Large SQL files can hit the browser upload limit. Compressing the file as .gz shrinks it a lot. If it still does not fit, open a ticket.

Remote connections (Remote MySQL)

By default only the server itself can connect to your database. To connect from a desktop tool on your computer, add your IP address under Databases > Remote Database Access, and remove it when you are done. The standard MySQL port is 3306; make sure your network allows it.

Troubleshooting

ErrorCauseFix
Error establishing a database connectionWrong name, user or passwordUse the full prefixed names; reset the password under MySQL Users.
Access denied for userUser not added to the databaseRepeat the Add User To Database step.
"#1044" or "#1227" on importThe SQL file references another database name or a DEFINERRemove the CREATE DATABASE / USE lines and any DEFINER= clauses from the file.

Frequently asked questions

Why does my database name have a prefix?

On a shared server cPanel adds your account username to every database and user so names never clash. Use the full name in your application.

Can one user access several databases?

Yes, but a separate user per site is safer: a weakness in one site does not expose the others.

What happens if I change the database password?

You must update the password in your application's config file too, or the site will show a connection error.

Need help moving a database? Open a ticket from the client area. Plans tuned for WordPress: WordPress hosting.

Was this article helpful?
Thank you for your feedback.