How to Drop a User in MySQL

From Brian Nelson Ramblings
Revision as of 20:46, 16 May 2014 by Brian (Talk | contribs) (Find the users accounts to remove)

Jump to: navigation, search

How to Drop a User in MySQL

Adding a user is pretty simple, but they never tell you how to remove a user from the system.

After removing an application from the server you will want to remove that user from MySQL as well.

Find the users accounts to remove

select user,host from mysql.user;

Output:

mysql> select user,host from mysql.user;
+-----------+----------------------+
| user      | host                 |
+-----------+----------------------+
| brian     | %                    |
| root      | 127.0.0.1            |
| wordpress | 127.0.0.1            |
| root      | ::1                  |
| brian     | localhost            |
| root      | localhost            |
| wordpress | localhost            |
+-----------+----------------------+

Now lets remove the wordpress user from MySQL.

Once logged into mysql as root run the following:

revoke all privileges, grant option from 'wordpress'@'127.0.0.1';
revoke all privileges, grant option from 'wordpress'@'localhost';
drop user 'wordpress'@'127.0.0.1';
drop user 'wordpress'@'localhost';