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.
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.
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.
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.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions