Command denied to user for table
Production Risk
Medium — operation is blocked; application functionality may be degraded.
ER_TABLEACCESS_DENIED_ERROR (1142, SQLSTATE 42000) is raised when a user attempts a command (SELECT, INSERT, UPDATE, DELETE, etc.) on a table for which they lack the required privilege.
- 1Application database user lacks the required table-level privilege
- 2GRANT was executed but FLUSH PRIVILEGES was not called (older MySQL versions)
- 3User connected to the wrong database or with the wrong host pattern
-- As limited user: INSERT INTO sensitive_table VALUES (1, 'data');
expected output
ERROR 1142 (42000): INSERT command denied to user 'app_user'@'localhost' for table 'sensitive_table'
Fix
Grant the required privilege
WHEN The user legitimately needs access.
GRANT INSERT ON mydb.sensitive_table TO 'app_user'@'localhost'; FLUSH PRIVILEGES;
Why this works
Table-level GRANT provides fine-grained control over which commands each user can execute on specific tables.
✕ Grant ALL PRIVILEGES to the application user to stop 1142 errors
Granting ALL PRIVILEGES gives the application user root-level access; use the principle of least privilege and grant only what is needed.
MySQL 8.0 — 1142 ER_TABLEACCESS_DENIED_ERROR
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev