Name

DROP USER

Synopsis

DROP USER 'user'@'host'

Use this statement to delete privileges for a user by deleting the row for that user and host, given the user table of the mysql database. This statement won’t delete a user that has any privileges set to `Y', though. To be assured that the user has no privileges, issue a REVOKE statement. You will have to issue a separate statement for each host for which the user has privileges.

REVOKE ALL ON *.* FROM 'rstringer'@'localhost';
DROP USER 'rstringer'@'localhost';

The ALL option is used to assure revocation of all privileges. The *.* covers all tables in all databases. Prior to Version 4.1.1 of MySQL, you would have to issue the following instead of a DROP USER statement:

DELETE FROM mysql.user
   WHERE User='rstringer' AND Host='localhost';
FLUSH PRIVILEGES;

Notice that the FLUSH PRIVILEGES statement is necessary so that the preceding DELETE statement takes effect immediately. It’s not necessary after the DROP USER statement, though.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.