How to Revoke Privileges from a MySQL User

May 9, 2023 / MySQL

This guide explains how to revoke privileges from a MySQL user.

The syntax for it would be as follows:

REVOKE privilege_type [(column_list)]
   [, priv_type [(column_list)]]...
ON [object_type] privilege_level
FROM user [, user]...

An explanation of the above outlined syntax is given below:

  1. First of all, specify the list of privileges that you want to revoke from the user after the REVOKE keyword. Separate privileges using commas.
  2. Specify the privilege level at which privileges is revoked in the ON clause.
  3. Lastly, specify the user account that you are supposed to revoke the privileges in the FROM clause.

For Example:

mysql> SHOW GRANTS FOR Admin@localhost;
+---------------------------------------------------------------------+
| Grants for Admin@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'Admin'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)

The following query will revoke the grants from user  “Admin@localhost”.

mysql> REVOKE ALL PRIVILEGES,GRANT OPTION FROM abcd@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW GRANTS for abcd@localhost;
+------------------------------------------+
| Grants for Admin@localhost                |
+------------------------------------------+
| GRANT USAGE ON *.* TO 'Admin'@'localhost' |
+------------------------------------------+
1 row in set (0.00 sec)

That’s it! In this way you can revoke privileges from a MySQL user.

Spread the love