Blog · WebJi® India

How to Create a MySQL Database in cPanel

Quick answer: In cPanel open Databases, then MySQL Databases, and create the database, then a user, then add that user to the database with ALL PRIVILEGES. Put the prefixed names, the password and localhost into wp-config.php. It worked when the site loads and phpMyAdmin lists the tables.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Indian designers reviewing website wireframes together on a studio monitor — how to create mysql database in cpanel

What a cPanel database is made of

A cPanel database is three records: a database, a MySQL user, and that user's privileges on the database. None of them is usable alone. Creating all three in Databases, then MySQL Databases takes about two minutes, and the names carry your account prefix.

  • Database name: up to 64 characters, and each underscore counts as two. With prefixing on, 63 characters including the prefix.
  • User name: separate from your cPanel login and from any mailbox.
  • Password: cPanel stores it but will not show it again, so save it when you create the user.
  • Prefix: your account username and an underscore come first, so wp is stored as user_wp.

Do not create the database in phpMyAdmin. On a cPanel hosting account, cPanel keeps a map of the databases it owns, and a database made outside that tool is not in the map, which breaks backup and restore. phpMyAdmin is for tables, imports and exports.

Create the database and user in MySQL Databases

The full manual route lives on one page: Databases, then MySQL Databases. Its blocks sit in order, so work down the page.

  1. In Create New Database, type a short name such as shop. The prefix is outside your control, so the database becomes user_shop.
  2. Click Create Database, then Go Back. The name now appears in Current Databases.
  3. Scroll to MySQL Users. Enter a username and password, or use Password Generator, and click Create User. Copy the password now.
  4. In Add User To Database, choose the user and the database, then click Add.
  5. On MySQL Account Maintenance tick ALL PRIVILEGES, then click Make Changes.
  6. Read Current Databases again. The user must appear under Privileged Users for that database.

You know it worked when the database row lists the user as a privileged user and no warning is shown. A database without that row is a database no script can use, which is the usual cause of the connection error further down this page.

Create the website database with the wizard

MySQL Database Wizard does the same three steps on one screen: name, user, privileges. It is the quicker route for a first WordPress install.

  1. Open Databases, then MySQL Database Wizard.
  2. Type the database name and click Next Step.
  3. Type the user name and a password, then click Create User. The strength meter turns green on a good one; keep it.
  4. Tick ALL PRIVILEGES and click Next Step.
  5. The last screen shows the database name, user and host. Copy all three before you click Finish.

If the wizard answers that the database already exists, the name is taken, sometimes by a database you deleted without dropping. Choose another name instead of guessing at the old one.

Connect the site with the host name, user and password

cPanel sites connect over localhost, so DB_HOST is localhost, not an IP and not the domain. The database name and the user both need the prefix, and a new site with a database uses the same four values.

  1. Open File Manager, then public_html, and edit wp-config.php after making a .bak copy; the File Manager guide shows that step.
  2. Set DB_NAME to the full prefixed name, DB_USER to the prefixed user, DB_PASSWORD to the saved password, and DB_HOST to localhost.
  3. Save, then load the site and wp-admin in a private window.
  4. In Databases, open phpMyAdmin and confirm the tables are listed on the left.

You know it worked when wp-admin loads without the connection error and phpMyAdmin shows at least one table. An empty database is correct before the installer runs; the tables arrive when WordPress or your own script writes them.

Remote MySQL is a different control. Databases, then Remote MySQL adds one allowed host for connections from your laptop or an office server. It does not change DB_HOST for the site, and it cannot open a port the host blocks; if a remote client times out, email support@webji.services with the client IP.

Create a database with a phpMyAdmin query

phpMyAdmin's SQL tab accepts CREATE DATABASE, and on a permissive account it creates one. cPanel will not list it, because only its own tool writes the database map, and that map is what backup and restore follow.

Run the query only inside a database you already own, for tables or test data. For a new database, use MySQL Databases and then open phpMyAdmin for the contents. Import loads a .sql or .sql.gz dump into the selected database; Export writes one out, which is how you take a copy before a migration. The backup guide covers the files side.

Fix Error establishing a database connection

That message means WordPress could not use the four values in wp-config.php. Match the symptom, change one value, reload.

SymptomCheck
Error on a fresh installDB_NAME and DB_USER in wp-config.php must include the account prefix.
Password was changedOpen MySQL Users, click Change Password, and paste the new one into wp-config.php.
User is not on the databaseCurrent Databases must list the user under Privileged Users.
Only SELECT was grantedAdd the user to the database again and tick ALL PRIVILEGES.
Database has disappearedThe name is gone from Current Databases; restore it or create it again.
Site moved to a new hostDB_HOST is still localhost, and the dump was imported into the new database.

If the page stays blank, read the PHP error log; the PHP error logs guide shows where cPanel writes it. A wrong password and a missing grant produce the same page, which is why the privilege row is the first check.

Read 1045 and 2002: access denied vs cannot connect

MySQL error 1045 is access denied: the server answered, then refused the user name, the password, or the host the client came from. Error 2002 is cannot connect: nothing answered on the socket or host you named.

  • 1045 from the site: compare DB_USER and DB_PASSWORD character by character, prefix included.
  • 1045 from a remote client: the user exists but is not allowed from that address; add the IP in Remote MySQL.
  • 2002 from the site: DB_HOST is not localhost, or the database server is down. Email support before editing further.
  • 2002 from a remote client: the host name is wrong, or port 3306 is closed to the outside.

Neither number is about the contents of the database, so a backup import will not clear them. Fix the connection first, then confirm in phpMyAdmin that the tables are intact.

Frequently Asked Questions

How do I create a MySQL database in cPanel?

Open Databases, then MySQL Databases. In Create New Database type a name and click Create Database, then Go Back. Scroll to MySQL Users, create a user with a password, then in Add User To Database pick both and tick ALL PRIVILEGES before Make Changes.

What is the MySQL hostname in cPanel?

localhost. That is the DB_HOST value in wp-config.php, because the database runs on the same server as the site. A Remote MySQL host appears only when the host has configured one, and that address is for connections from outside, not for the site's own PHP.

Why does WordPress say Error establishing a database connection?

One of four things: the name or user is missing the account prefix, the password is wrong, the user was never added to the database, or ALL PRIVILEGES was not granted. Open MySQL Databases and compare all four against wp-config.php.

What is the difference between MySQL error 1045 and 2002?

1045 is access denied: the server was reached and rejected the user or the password. 2002 is cannot connect: the host or socket was wrong, or the server was not listening. Fix the credentials for 1045 and the host name for 2002.

Can I create a database with a phpMyAdmin query?

A CREATE DATABASE statement can run if your user holds the right, but cPanel will not add that database to its map, so backup and restore can miss it. Create the database in MySQL Databases and use phpMyAdmin for tables, imports and exports.

How do I import a .sql file in cPanel?

Open phpMyAdmin from Databases, select the database on the left, open Import, choose the .sql or .sql.gz file and click Import. The database must exist first, and a very large dump may need to be split or sent to support.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →