Knowledgebase / cPanel & hosting
How do I create a MySQL database in cPanel?
Create a MySQL database and user in cPanel, grant the right privileges, and collect the four connection details your application needs.
Most website software stores its content in a database rather than in files. This guide covers creating a MySQL database, creating a user for it, and giving that user access, so you end up with the four details an installer asks for: database name, username, password, and host. Start by logging in to cPanel.
If you are installing WordPress through Softaculous, it creates the database for you and you can skip this guide.
Create the database
- In cPanel, find the Databases section and open MySQL Databases.
- Under Create New Database, type a short name. The site or project name works well.
- Click Create Database.
cPanel puts your account username and an underscore in front of the name, so a database you call "shop" is stored as something like "youruser_shop". Use that full prefixed name wherever an application asks for the database name. There is a length limit on the combined name, and cPanel will tell you on screen if the name you chose is too long.
Create a database user
Stay on the same page and scroll down to MySQL Users.
- Enter a username. The same account prefix is added automatically.
- Click Password Generator and use the password it offers, or type your own. Copy the password and store it somewhere safe before you continue, because cPanel will not show it again.
- Click Create User.
Give each database its own user rather than sharing one user across several sites. If one set of credentials is ever exposed, the damage stays with that single database.
Give the user access
A new user has no access to anything until you grant it.
- Scroll to the Add User To Database section.
- Choose your new user and your new database from the two menus, then click Add.
- On the privileges screen, tick ALL PRIVILEGES, then click Make Changes.
Most applications need full rights on their own database so they can create and alter their tables during installation and updates.
Use the connection details
Your application now needs four values:
- Database name: the full prefixed name, such as youruser_shop
- Username: the full prefixed username
- Password: the one you saved in the previous step
- Database host: usually localhost, because the site and the database run on the same server
If you need to connect from your own computer or from a server elsewhere, add that IP address under Remote MySQL first. To confirm the database exists and the login works, open phpMyAdmin from the Databases section and look for your database in the left-hand list.
If it didn't work
- The prefix was left out. "shop" and "youruser_shop" are different names, and an installer given the short version reports that it cannot find the database.
- The user was created but never added to the database, or privileges were not ticked. Reopen MySQL Databases and check that the user is listed under your database with ALL PRIVILEGES.
- The password was mistyped or contains a character your application's configuration file treats specially. Setting a fresh generated password under Change Password in MySQL Users is faster than hunting for the cause.
If the application still cannot connect after those checks, open a ticket at /support with the exact error message and the database name, and we will look at it from the server side.
More in cPanel & hosting
Stuck partway through? Support is answered by the engineers who run the servers, around the clock.