Location : PHP Hosting - Web Hosting Knowledge Base - PHP MySQL Tutorial

Delete MySQL database and user

Removing MySQL Database

MySQL database takes up significant server resources, it is recommended to remove unwanted MySQL databases from your hosting account if you no longer need it. Furthermore, most of the hosting account has limited MySQL database creation, removing unwanted database can free up resources for new database creation.

NOTE: Be sure to backup your databases before removing it if you need a copy of the data.

Removing MySQL Database in Cpanel hosting account

Below list the steps for removing a mysql database in a typical cpanel hosting environment: -

  1. Login to hosting account control panel
  2. click on SQL database to enter the database management screen.
  3. From the list of available MySQL databases, select the database to be deleted and click on the Delete button next to the database name to remove the database.

Removing MySQL Database in command prompt

For Linux user that have access to the hosting account command prompt, you can issue a mysql command directly through the mysql shell to delete a database, please note that you will require sufficient permission granted in mysql for your userid in order to perform these tasks, below shows the steps :-

  1. SSH logging to your hosting account
  2. at the Linux command prompt, enter mysql to startup the mysql shell
  3. in the mysql shell prompt, enter DROP DATABASE database_name; to delete the database from the mysql server

Removing MySQL user

MySQL users that has been granted access to the deleted database will not be automatically remove in the MySQL database removal process, you will need to remove the MySQL user separately if the user is no longer needed.

NOTE: One MySQL user may have been granted access to several databases, so be careful not to remove a user that is still needed to access other databases.

Remove MySQL user in a cpanel hosting account

  1. Login to your hosting account control panel, click on SQL database option
  2. To remove a mysql user, locate the user from the Current User section
  3. hit Delete button next to the MySQL username you wish to remove.

Removing MySQL user from command prompt

NOTE: certain commands in mysql shell requires higher access level granted, you may or may not be able to perform the task in mysql shell if your userid does not have enough access permission granted. If you are not familiar with shell commands, it is advisable to follow the web host's instruction to perform the task through hosting account control panel.

  1. SSH in to your hosting account, enter mysql to bring up mysql shell
  2. enter the command DELETE FROM user WHERE user='mysql_user_name';