Creating and setting up MySQL database in cPanel

  John Mwaniki /    Updated on 07 Jul 2024

Many new web developers find it challenging to create and set up a database for the very first time when taking their website online.

This is because unlike in local web servers which they are used to (eg. XAMPP, WAMPP, LAMPP, etc), the PhpMyAdmin in cPanel(hosting account control panel) does not allow you to create or delete a database but only gives you option to manage it.

In this tutorial, we will go into a step-by-step procedure on how to create and set up new MySQL databases in cPanel.

You can create it using two options on cPanel:

  • My databases option
  • Database wizard option

1. My Databases

Step 1: Click “MySQL Databases” under databases section.

cPanel mysql databases

Step 2: Under Create New database, enter your preferred DB name and click the “Create Database” button.

cPanel mysql databases create new database

The database will be created with the name prefixed by cPanel username and underscore.

The created database will be visible under the "current databases" table.

cPanel current databases

Step 3: Creating a database user.

You need to create a user for your database or use an existing user(if there already exists a user).

To create a user:

- Scroll down to the “Add new User” form.

- Enter your preferred username and create a strong password for your user. The username too will be prefixed with the cPanel username and underscore.

Creating database user in cpanel

The just created DB user will be listed under current users.

MySQL database user in cPanel

Step 4: Assigning the user to the database. Under the “Add user to database” form make sure the right database and the user for that database are selected then click “Add”.

Assigning a user to a MySQL database in cPanel

Step 5: Set user privileges for the management of the database. Tick all the options that you want to allow the user to do. If you want to give the user all privileges, click on the “All privileges” option.

Click on the “Make Changes” button.

Setting permissions for MySQL database user in cPanel

Now you will use the database name, database username and password you just created for connection in the code.

The other database stuffs such creation of tables will be done under PhpMyAdmin, which is still in the “Databases” section.

 

2. Database Wizard

This is the easier and faster version of doing all that you have learned above.

Step 1: Click on “MySQL Database Wizard”.

cPanel MySQL database wizard

Step 2: Enter the database name and click “Next Step”.

Creating a database with MySQL database wizard

Step 3: Create a database user. Enter the username and strong password then click “Create User”.

Creating a dataase user with MySQL database wizard

Step 4: Set privileges for the database user as discussed above and click “Next Step”.

Setting DB user permissions with MySQL wizard

You can click on “Return to MySQL Databases” to view your newly created database.

Database created with MySQL wizard

Accessing MySQL database with PhpMyAdmin

Now the database has been created and can be accessed and managed with PhpMyAdmin.

To do that:

Click the "PhpMyAdmin" link under the "Databases" section of cPanel.

cPanel PhpMyAdmin

You will now be able to see your newly created database. From here, you can do all the database operations the same way as in XAMPP and WAMPP PhpMyAdmin.

Databases in cPanel PhpMyAdmin