Error
Error Code:
1142
MySQL Error 1142: Command Denied on Table
Description
This error indicates that a MySQL user attempted an operation (e.g., SELECT, INSERT, UPDATE) but lacks the necessary privileges for the specified table. It's a security measure preventing unauthorized access or modifications to your database.
Error Message
%s command denied to user '%s'@'%s' for table '%s'
Known Causes
4 known causesInsufficient User Privileges
The MySQL user does not have the required GRANT privileges (e.g., SELECT, INSERT, UPDATE) for the specific table or database.
Incorrect User or Host
The application or client is connecting with a user account or from a host that lacks the necessary permissions, or a different user is active than intended.
Privilege Cache Not Refreshed
Recent changes to user privileges might not have been reloaded by the MySQL server, causing old permissions to remain enforced.
Overridden Table-Level Permissions
Despite broader database or global privileges, specific table-level DENY or more restrictive GRANT statements can override them.
Solutions
5 solutions available1. Grant Required Privilege easy
Give user permission for the specific command
1
Connect as admin and grant privilege
mysql -u root -p
2
Grant SELECT privilege
GRANT SELECT ON database_name.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
3
Grant multiple data privileges
GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
2. Grant Schema Modification Privileges medium
Allow CREATE, ALTER, DROP operations
1
Grant DDL privileges
GRANT CREATE, ALTER, DROP, INDEX ON database_name.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
2
Grant for stored procedures
GRANT CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON database_name.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
3. Grant Table-Specific Permissions medium
Limit access to specific tables
1
Grant on specific table
GRANT SELECT, INSERT, UPDATE ON database_name.users TO 'username'@'localhost';
FLUSH PRIVILEGES;
2
Grant on specific columns
GRANT SELECT (id, name, email), UPDATE (name) ON database_name.users TO 'username'@'localhost';
FLUSH PRIVILEGES;
4. Check and Fix User Privileges easy
View current permissions and add missing ones
1
Check current grants
SHOW GRANTS FOR 'username'@'localhost';
2
Identify which privilege is denied from error
-- Error: SELECT command denied
-- Solution: GRANT SELECT ...
-- Error: UPDATE command denied
-- Solution: GRANT UPDATE ...
-- Error: CREATE command denied
-- Solution: GRANT CREATE ...
5. Grant All Privileges (Development Only) easy
Full access for development environments
1
Grant all on specific database
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
FLUSH PRIVILEGES;