← Back to Chapters

MySQL REVOKE Permissions

? MySQL REVOKE Permissions

? Quick Overview

The REVOKE statement in MySQL is used to remove previously granted privileges from a user. It helps database administrators control access and maintain security by restricting what actions a user can perform.

? Key Concepts

  • Permissions are removed using the REVOKE command
  • Privileges can be revoked at global, database, table, or column level
  • Changes take effect immediately after execution
  • Usually combined with GRANT for access control

? Syntax / Theory

The basic syntax of the REVOKE command removes one or more privileges from a specific user and host.

? View Code Example
-- General syntax to revoke privileges in MySQL
REVOKE privilege_name
ON database_name.table_name
FROM 'username'@'host';

? Code Example(s)

The following example revokes the INSERT and UPDATE permissions from a user on a specific database table.

? View Code Example
-- Revoke INSERT and UPDATE permissions from user 'app_user'
REVOKE INSERT, UPDATE
ON company_db.employees
FROM 'app_user'@'localhost';

? Live Output / Explanation

What Happens?

After executing the above command:

  • The user app_user can no longer insert or update rows
  • Other permissions like SELECT remain unchanged
  • No server restart is required

✅ Tips & Best Practices

  • Always check current privileges using SHOW GRANTS
  • Revoke only necessary permissions to follow least privilege principle
  • Be specific with database and table names
  • Use FLUSH PRIVILEGES only when modifying system tables manually

? Try It Yourself

Practice revoking permissions safely:

? View Code Example
-- Check existing permissions for a user
SHOW GRANTS FOR 'test_user'@'localhost';

-- Revoke SELECT permission from a database
REVOKE SELECT
ON sample_db.*
FROM 'test_user'@'localhost';

After running the commands, try querying the database as test_user to observe the permission change.