MySQL Error 1144 is a common roadblock for database administrators and developers. The error message “Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used” indicates that there’s a problem with the syntax of a GRANT or REVOKE statement, specifically that the privileges attempted to be granted or revoked are not applicable in the given context. This error can be easily addressed by understanding MySQL’s privilege system and ensuring that the correct privileges are assigned appropriately.
Understanding the Error
MySQL’s privilege system is designed to be very granular, allowing specific types of permissions to be assigned to users over database objects such as tables, schemas, and the server itself. Error 1144 occurs when you attempt to grant a privilege that doesn’t exist or isn’t applicable to the specified database object.
Diagnosing the Problem
To fix this error, you need to:
- Understand which privileges are valid for the object you are trying to secure.
- Check the syntax of your GRANT or REVOKE statement to ensure it’s correct.
You can consult the MySQL documentation to see a list of valid privileges for different types of objects.
Fixing the Error
Here are some examples where Error 1144 might occur, along with the correct approach to resolve it:
Example 1: Granting Table-Level Privileges Incorrectly
Incorrect usage:
GRANT SUPER ON mydb.mytable TO 'user'@'localhost';
The SUPER
privilege is a global privilege and cannot be granted at the table level. To fix this, you need to grant a privilege that is valid for a table, such as SELECT
, INSERT
, UPDATE
, etc.:
Correct usage:
GRANT SELECT ON mydb.mytable TO 'user'@'localhost';
Example 2: Revoking Server-Level Privileges Incorrectly
Incorrect usage:
REVOKE FILE ON *.* FROM 'user'@'localhost';
The REVOKE
statement syntax is incorrect here because the FILE
privilege is a global privilege and must be revoked at the global level:
Correct usage:
REVOKE FILE ON *.* FROM 'user'@'localhost';
Example 3: Using Non-Existent Privileges
Incorrect usage:
GRANT EXECUTE ON mydb.mytable TO 'user'@'localhost';
The EXECUTE
privilege does not apply to tables but to stored routines. If you intended to grant privileges on a stored procedure or function, the syntax should be:
Correct usage:
GRANT EXECUTE ON PROCEDURE mydb.myprocedure TO 'user'@'localhost';
-- or for a function
GRANT EXECUTE ON FUNCTION mydb.myfunction TO 'user'@'localhost';
Example 4: Granting Privileges on Non-Existent Databases or Tables
Incorrect usage:
GRANT SELECT ON non_existent_db.* TO 'user'@'localhost';
Ensure the database or table you are granting privileges on actually exists. If not, create it or correct the database/table name:
Correct usage:
GRANT SELECT ON existing_db.* TO 'user'@'localhost';
Conclusion
When you encounter MySQL Error 1144, carefully review the privileges you are trying to grant or revoke, and compare them against the MySQL documentation to ensure they are valid for the targeted object. Adjust your GRANT or REVOKE statements accordingly to reflect the correct privileges and object types. With a clear understanding of MySQL’s privilege system and proper syntax, you can effectively manage user permissions and avoid this error.
For a comprehensive overview of MySQL privileges and their correct usage, the MySQL Documentation on Privileges is an invaluable resource. Additionally, platforms like Stack Overflow provide community-driven support for troubleshooting common MySQL errors, including Error 1144.