How to create and manage a MySQL Database in cPanel

From cPanel you cannot directly create or upload your database using PHPMyAdmin while making your website live. You need to follow some of the steps like – creating a database, user, etc.

The cPanel gives easy to use interface that makes it easier to manage the database and make it available in the PHPMyAdmin.

In this tutorial, I am assuming that you already have a cPanel enabled web hosting server.

How to create and manage a MySQL Database in cPanel


Contents

  1. Create a MySQL database
  2. Create user for database
  3. Assign user to MySQL database
  4. Import tables using phpMyAdmin
  5. Update database Configuration
  6. Conclusion

1. Create a MySQL database

  • Login to your cPanel account.

Login to cPanel account for database creation

  • Click on MySQL Databases under Databases section.

Open MySQL databases page from cPanel

  • Enter the name of the database and click on the Create Database button.

Enter name of database in cPanel

  • The database is now created.

2. Create user for database

  • Navigate to Add New User section.
  • Enter the username and password. You can use Password Generator to create a strong password.

Create a user for database in cPanel

  • Click on the Create User button.

3. Assign user to MySQL database

  • Navigate to Add User To Database.
  • Here, select your created user and Database from the drop-down.

Assign user to the MySQL database

 

  • Click on the Add button.
  • You will be taken to the Manage User Privilege section. Here, check the All Privileges checkbox and click on Make Changes button.

Manage user permissions on MySQL database

 


4. Import tables using phpMyAdmin

  • Back to cPanel Home and click on the phpMyAdmin under Databases section.

Open phpMyAdmin in cPanel

  • Find your created database and import the tables or create a new one.

5. Update database Configuration

Now update your database configuration in your project. Replace database, username, and password.

Example

<?php

$host = "localhost"; /* Host name */
$user = "webtechh_newuser"; /* User */
$password = "123456"; /* Password */
$dbname = "webtechh_newdatabase"; /* Database name */

$con = mysqli_connect($host, $user, $password,$dbname);
// Check connection
if (!$con) {
   die("Connection failed: " . mysqli_connect_error());
}

6. Conclusion

After creating the database require assigning a user for this you can either use the existing users or create a new one. You can change the user privileges on the database.

Make sure to update your project database configuration after creating and assigning the user to the database.

If you found this tutorial helpful then don't forget to share.

Leave a Comment