Dienstag, 11. März 2014

Deleting/removing/revoking a User from a MySQL Database

Depending on the version of MySQL you use, there are different methods of deleting a user.
As of MySQL 5.0.2, you can remove an account and its privileges as follows:

   DROP USER user;


If this does not work, try:

   DROP USER 'user'@'localhost';


In older versions of MySQL you need to 'revoke' granted priviledges from a user:

   REVOKE ALL PRIVILEGES, GRANT OPTION FROM user;


..which drops all global, database, table, column, and routine privileges for the named user.

To see the priviledges granted for a given account simply:


   SHOW GRANTS FOR 'user'@'localhost';

Before MySQL 4.1.1, DROP USER is not available. You should first revoke the account privileges using SHOW GRANTS and REVOKE as just described. Then delete the user table row and flush the grant tables as shown here:

   DELETE FROM mysql.user WHERE User='user' and Host='localhost';

Update the priviledges with FLUSH:

       FLUSH PRIVILEGES;

See https://dev.mysql.com/doc/refman/5.0/en/drop-user.html
and https://dev.mysql.com/doc/refman/4.1/en/drop-user.html for further documentation.

Keine Kommentare:

Kommentar veröffentlichen