Creating and setting up MySQL database in cPanel
John Mwaniki / Updated on 07 Jul 2024Many 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.
Step 2: Under Create New database, enter your preferred DB name and click the “Create Database” button.
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.
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.
The just created DB user will be listed under current users.
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”.
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.
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”.
Step 2: Enter the database name and click “Next Step”.
Step 3: Create a database user. Enter the username and strong password then click “Create User”.
Step 4: Set privileges for the database user as discussed above and click “Next Step”.
You can click on “Return to MySQL Databases” to view your newly created database.
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.
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.