How to Remove MySQL Databases and Users

You may spend a good portion of any given day adding users and databases to your MySQL server, but you might not spend much time removing them, even after you or your users no longer need them. Nevertheless, it is very important to not leave unattended databases and users lying around for would-be attackers to hijack. Therefore, the following brief tutorial is very important for any database administrator.

Removing Databases

To remove a database from MySQL, follow this simple formula:

mysqladmin -u[username] -p[password] drop [database]

For example, if you have a database called “serverschool” with a username of “dss” and a password of “tooeasy”, you would type this from the command line:

$ mysqladmin -udss -ptooeasy drop serverschool

For username and password, any user that has the necessary privileges will do, or you can use your root username and password.

Removing Users

From within the mysql prompt, you need to revoke user privileges and then drop the user as follows:

mysql> show grants for ‘dss’@’localhost’;

mysql> revoke all privileges, grant option from ‘dss’@’localhost’;

mysql> drop user ‘dss’@’localhost’;

If you use some type of hosting automation, you can often also use your control panel or frontend to remove databases or users. For more information about either procedure, see the online documentation.