How do I create a MySQL database, user, and then delete if needed? Print

  • 46

Introduction: This article will guide you through the process of creating, managing, and deleting MySQL databases and users in cPanel. We will also discuss user privileges and how to connect to your database using PHP code. For additional resources, please visit our Knowledgebase at https://www.domainindia.com/login/knowledgebase.

Creating a MySQL Database in cPanel:

  1. Log in to your cPanel account.
  2. Click on "MySQL Databases" under the "Databases" section.
  3. In the "Create New Database" field, enter a name for your database. Note that cPanel will create the full name as "cpaneluser_databasename."
  4. Click the "Create Database" button.

You have now successfully created a MySQL database. Next, you will need to create a user to access the database.

Creating a User for the MySQL Database:

  1. In the "MySQL Databases" section, scroll down to the "MySQL Users" subsection.
  2. In the "Username" field, enter a username for the database user. Note that the full username will be "cpaneluser_databaseuser."
  3. In the "Password" field, enter a password for the database user.
  4. Click the "Create User" button.

You have now created a database user. To manage your database, you can use phpMyAdmin, which is available in the "Databases" section of cPanel.

Assigning User Privileges to the MySQL Database:

  1. In the "MySQL Databases" section, scroll down to the "Add User to Database" subsection.
  2. From the "User" dropdown menu, select the user you want to grant privileges to.
  3. From the "Database" dropdown menu, select the database you want the user to access.
  4. Choose the privileges you want the user to have by checking the appropriate boxes.
  5. Click the "Add User to Database" button.

You have now created a new database with a privileged user. You can now input this information into a PHP script or another script to access the database locally.

Deleting a MySQL Database and User:

  1. In the "MySQL Databases" section, locate the "Current Databases" subsection.
  2. Click "Delete" next to the database you want to remove.
  3. (Optional) If you also want to remove the user associated with the database, locate the "MySQL Users" subsection and click "Delete" next to the user.

You have now successfully deleted a MySQL Database and, optionally, its associated user.

For more information on connecting to a MySQL database using PHP code, please refer to our Knowledgebase articles:

  1. https://www.domainindia.com/login/knowledgebase/103/How-to-connect-to-the-MySQL-database.html
  2. https://www.domainindia.com/login/knowledgebase/226/Connecting-to-a-MySQL-Database-with-PHP-Code-in-cPanel-and-DirectAdmin.html

Conclusion: Managing MySQL databases and users in cPanel is a straightforward process. By following these steps, you can create, manage, and delete databases and users with ease. Don't forget to visit Domain India's Knowledgebase for more helpful resources and guidance.


Was this answer helpful?

« Back