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.
REVOKE commandGRANT for access controlThe basic syntax of the REVOKE command removes one or more privileges from a specific user and host.
-- General syntax to revoke privileges in MySQL
REVOKE privilege_name
ON database_name.table_name
FROM 'username'@'host';
The following example revokes the INSERT and UPDATE permissions from a user on a specific database table.
-- Revoke INSERT and UPDATE permissions from user 'app_user'
REVOKE INSERT, UPDATE
ON company_db.employees
FROM 'app_user'@'localhost';
After executing the above command:
app_user can no longer insert or update rowsSELECT remain unchangedSHOW GRANTSFLUSH PRIVILEGES only when modifying system tables manuallyPractice revoking permissions safely:
-- 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.