← Back to MySQL Course | Chapter 18: User Management & Security | Lesson 3 of 6

REVOKE Privileges

What is REVOKE?

REVOKE is the direct opposite of GRANT — instead of handing out a permission, it removes one that was previously assigned, which is essential when a user's role changes or a project they had access to wraps up.

Example: What is REVOKE?

sql
REVOKE INSERT ON mydb.* FROM 'app_user'@'localhost';

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Revoking All Privileges

Revoking every privilege from an account at once leaves the login itself intact but strips it of any ability to act on the database, effectively neutralizing the account without deleting it outright.

Example: Revoking All Privileges

sql
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'app_user'@'localhost';

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Revoking Specific Column Privileges

Just as column-level privileges can be granted, they can also be revoked individually, removing access to one specific column while leaving the user's permissions on every other column of that table unchanged.

Example: Revoking Specific Column Privileges

sql
REVOKE SELECT (salary) ON mydb.employees FROM 'app_user'@'localhost';

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Applying Revocations

After revoking permissions, running a flush command ensures the change takes effect right away rather than waiting for cached privilege data to refresh on its own.

Example: Applying Revocations

sql
REVOKE INSERT ON mydb.* FROM 'app_user'@'localhost';
FLUSH PRIVILEGES;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Common Mistakes with REVOKE

A REVOKE statement must match the exact scope of the original GRANT — you can't remove a database-level permission using a broader global wildcard, so the syntax has to mirror how the access was originally granted.

Example: Common Mistakes with REVOKE

sql
-- Granted at the database level:
GRANT SELECT ON mydb.* TO 'app_user'@'localhost';
-- Wrong: a broader global scope doesn't match the original grant
-- REVOKE SELECT ON *.* FROM 'app_user'@'localhost';
-- Correct: mirror the original scope exactly
REVOKE SELECT ON mydb.* FROM 'app_user'@'localhost';

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.