How to fix ERROR 1142: Command denied to user for table in MySQL
ERROR 1142 occurs when a MySQL user lacks the necessary table-level permissions to execute a command like SELECT, INSERT, UPDATE, or DELETE. Resolve this by granting the appropriate privileges and flushing the privilege cache.
Quick fix
Fixes 1142
SHOW GRANTS;- Check current user permissions
- Grant the missing table privileges
- Flush privileges to apply changes
- Verify the fix
SHOW GRANTS;ERROR 1142: Command denied to user for table
What this error means
ERROR 1142 (ER_TABLEACCESS_DENIED_ERROR) is a permission/authorization error in MySQL. It means the user account you're using has access to the database, but does not have permission to execute a specific command (SELECT, INSERT, UPDATE, DELETE, TRIGGER, etc.) on that particular table. This error occurs at the table level, not the database level. A user might have SELECT on some tables but not others, or might have INSERT but not UPDATE. The error message format is: "ERROR 1142 (42000): [COMMAND] command denied to user 'username'@'hostname' for table 'table_name'". MySQL uses a privilege hierarchy: global privileges > database privileges > table privileges. When a command is denied at the table level, it overrides higher-level grants.
Typical symptoms
- Database queries fail with "ERROR 1142" when running SELECT, INSERT, UPDATE, or DELETE statements
- Application throws "Syntax error or access violation: 1142" exception
- Stored procedures or triggers fail to execute with permission denied errors
- Some users can run commands on certain tables while others cannot
- Commands work fine locally (as root/admin) but fail for application or remote users
- Web applications or API endpoints suddenly stop accessing database tables
Common causes
- User account lacks table-level SELECT, INSERT, UPDATE, or DELETE permissions on the specific table
- User has database-level access but no explicit table-level grants for the operation
- Privileges were revoked but FLUSH PRIVILEGES was not executed to clear the cache
- Incorrect GRANT statement syntax used with wrong database or table name
- User connecting from a different hostname than what is specified in the GRANT statement (e.g., localhost vs 127.0.0.1)
- MySQL 8.0+ role-based access control (RBAC) configured without proper role permissions
- Shared hosting: insufficient database quota or user role restrictions
How to fix "ERROR 1142: Command denied to user for table"
First, identify what privileges your current user has. Connect to MySQL and run:
SHOW GRANTS;This will display all grants for your current user. If you need to check another user's permissions:
SHOW GRANTS FOR 'username'@'hostname';Look for the specific table in question. If there's no GRANT statement mentioning that table, that's the problem.
As a MySQL admin (root user or user with GRANT privilege), grant the necessary permissions. For a specific table:
GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.table_name TO 'username'@'hostname';For all tables in a database:
GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO 'username'@'hostname';If you only need SELECT (read-only access):
GRANT SELECT ON database_name.table_name TO 'username'@'hostname';Replace:
- username with the actual MySQL username
- hostname with the host from which the user connects (use % to allow from any host: 'username'@'%')
- database_name and table_name with actual names
After running GRANT, execute:
FLUSH PRIVILEGES;This clears MySQL's in-memory privilege cache, forcing it to reload from the privilege tables. Without this, changes may not take effect immediately (especially after GRANT statements that directly update privilege tables).
Note: When using GRANT or REVOKE directly, privilege tables are updated automatically, but flushing ensures all connections see the changes.
Test that the command now works. If you're fixing permissions for another user, you can switch to that user:
-- Check the user's new grants
SHOW GRANTS FOR 'username'@'hostname';Then try executing the problematic command. If you're using an application, reconnect to trigger a new database connection.
Advanced notes
Hostname Matching: MySQL user authentication combines username AND hostname. 'user'@'localhost' is different from 'user'@'127.0.0.1' or 'user'@'192.168.1.100'. If your user connects from a different host than what's in the GRANT statement, permissions won't apply. Use SHOW GRANTS FOR 'user'@'%' to see all grants for a user regardless of host, or use 'user'@'%' in the GRANT to allow connections from any host.
Trigger Permissions: Triggers require TRIGGER privilege in addition to the base command privilege: GRANT SELECT, TRIGGER ON database.table TO 'user'@'host';
Stored Procedures: If a stored procedure creates/modifies tables, the user needs CREATE or ALTER privileges, not just table-level command privileges.
MySQL 8.0+ Roles: Modern MySQL uses roles. If your account is assigned a role, check role permissions: SHOW GRANTS FOR 'user'@'host' USING role_name;
Shared Hosting: Some hosting providers restrict GRANT and FLUSH PRIVILEGES. Use cPanel/Plesk to manage user privileges through the GUI instead.
Root Cause Prevention: Always use the principle of least privilege—grant only the minimum permissions needed. Regularly audit privileges with SHOW GRANTS and remove unnecessary permissions.
Frequently asked questions
- What does "1142" mean?
- ERROR 1142 (ER_TABLEACCESS_DENIED_ERROR) is a permission/authorization error in MySQL. ) on that particular table. This error occurs at the table level, not the database level.
- How do I fix "1142"?
- ERROR 1142 occurs when a MySQL user lacks the necessary table-level permissions to execute a command like SELECT, INSERT, UPDATE, or DELETE. Resolve this by granting the appropriate privileges and flushing the privilege cache.
- What causes "1142"?
- User account lacks table-level SELECT, INSERT, UPDATE, or DELETE permissions on the specific table User has database-level access but no explicit table-level grants for the operation Privileges were revoked but FLUSH PRIVILEGES was not executed to clear the cache
- Is the "1142" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚MySQL Official Documentation
- 📖MySQL Error Reference (Official)(Official Docs)