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

REVOKE Privileges

REVOKE is like taking back a permission slip you gave earlier, so that person can no longer do that thing.
Syntax
sql
REVOKE privilege1, privilege2
ON database_name.table_name
FROM 'username'@'host';

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.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Revoking from a different host account than the one granted, like app_user@'%' instead of app_user@localhost.
  2. Expecting REVOKE to delete the account, when the user can still log in.
  3. Revoking a privilege that was granted at a different level, such as mydb.* when it was granted on *.*.
🔒

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.