HoganHost blog

[email protected]

How To Create or Delete a MySQL Database or User

We will show you how effortless it is to create the database and the database user and assign that user to your new database. This is standard practice for anyone looking to manually install third-party programs that make use of MySQL databases.

Disclaimer: Your cPanel may have a new look, but the steps should be relatively the same.

Create or Delete a MySQL Database

How To Create a MySQL Database

  1. Log in to cPanel.
  2. Look for the Databases section, then click MySQL Databases.                                                     
  3. In the New Database field, type a name for your database.                                                                
  4. Click Create Database.
  5. Click Go Back.
    • The new database will appear in the Current Databases section.

How To Delete a MySQL Database

  1. Navigate to the Current Databases section of MySQL Databases.
  2. In the Actions column of the table, click Delete next to the database you wish to delete.     
  3. Confirm that you wish to permanently remove the database.                                                            

Create or Delete a Database User

What is a MySQL User, and Why is it Important?

The MySQL user is a record in the MySQL server created for authentication purposes. This is different from the usernames you use in logging into Windows or even in your cPanel/WHM. Setting up a MySQL user provides more security to your website’s databases as you can assign permissions to each user. Aside from you, the website’s owner, you do not wish to grant just any user all access to your database.

After creating the database, you will need to create a user and assign privileges. Please note that MySQL user accounts must be created separately from mail and web administrator accounts.

How To Create a Database User

  1. Log in to cPanel.
  2. Look for the Databases section, then click MySQL Databases.                                               
  3. Click the Jump to MySQL Users link at the top-right corner of the page. You may also scroll a little bit down to the MySQL User section.
  4. Under Add New User, enter a username.                                                                                            
  5. Enter a password in the Password field.
    • For help generating a strong password, click the Generate Password button.
  6. Once the password is confirmed, click on the Create User button.

How To Delete a Database User

  1. Navigate to the Current Users section of MySQL Databases.
  2. Locate the database user you wish to delete, then click its Delete icon.                                     
  3. Click the Delete User icon to confirm the deletion.                                                                               

Define a User’s Privileges and How Important They Are

You need specific users to have permissions to perform website management tasks, like running queries or modifying databases. This is when we grant privileges. Privileges determine how a user is able to interact with the database. For example, privileges will dictate whether or not the user can add and delete information.

How To Assign Privileges to Database User

  1. Log in to cPanel.
  2. Look for the Databases section, then click MySQL Databases.                                                        
  3. Under Add User to Database, select a user from the User dropdown menu.                              
  4. From the Database dropdown menu, select the database you wish to allow the user access to.
  5. Click Add.
  6. On the next page, select the privileges you wish to grant the user or simply select ALL PRIVILEGES. 
  7. Click Make Changes, then click Go Back.

How To Unassign a User from a Database

  1. Navigate to the Current Databases section of MySQL Databases.
  2. Locate the database you wish to modify.
  3. In the Privileged Users column for that database, click the trash icon.                                          

Using the Database

Now that you can create databases and users and assign appropriate privileges, you can use the following articles as references in editing and connecting to your databases.

How To Delete a Database Without Using cPanel

The steps below are done using SSH. If you know how to use it.

  1. Make a backup of the database with SSH using the command line below. Use your cPanel password.
    [email protected] [~] # mysqldump --password username_database > username_database.db
    Enter password:  (cPanel Password)
    [email protected] [~] #
  2. Next, use the DROP DATABASE command, inside of mysql, to delete the database.
    mysql> SHOW DATABASES LIKE "username_database";
    | Database (username_database) |
    | username_database            |
    1 row in set (0.02 sec)
    mysql> DROP DATABASE username_database;
    Query OK, 0 rows affected (0.00 sec)
    mysql> SHOW DATABASES LIKE "username_database";
    Empty set (0.02 sec)

Go to DROP DATABASE Statement link for further information on this command.

How To Drop One or Multiple Users at a Time

Using the MySQL statement DROP USER allows you to remove user accounts and also their privileges from the database.


DROP USER ‘user’@’host’;
  • User: The user account you want to drop.
  • Host: The host server name of the user account. Format: ‘user_name’@’host_name’.


DROP USER ‘snappy01’@’localhost’;

To DROP multiple user accounts, follow this format:

DROP USER ‘snappy01’@’localhost’, ‘snappy02’@’localhost’;

How To Grant Privileges in MySQL

To grant privileges to users in MySQL, you are first required to have the CREATE USER and GRANT privileges.


GRANT permission1, permission2 ON database_name TO 'user'@'localhost';


GRANT SELECT, INSERT, DELETE ON example_db TO ‘snappy02’@’localhost’;

How To View Privileges in MySQL

To show existing users and their privileges in MySQL, run the command SHOW GRANT.


SHOW GRANTS FOR 'database_user'@'localhost';


SHOW GRANTS for ‘snappy02’@’localhost’;

Sample Output:

mysql> SHOW GRANTS FOR ‘snappy02’@'localhost';
| Grants for [email protected] |
| GRANT USAGE ON *.* TO `snappy02`@`localhost` |
| GRANT SELECT, INSERT, UPDATE ON `example_db`.* TO `snappy02`@`localhost` |



Leave a Comment

Your email address will not be published.