1142
MariaDBERRORNotableSecurityHIGH confidence

Command denied to user for table

Production Risk

Medium — operation is blocked; application functionality may be degraded.

What this means

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.

Why it happens
  1. 1Application database user lacks the required table-level privilege
  2. 2GRANT was executed but FLUSH PRIVILEGES was not called (older MySQL versions)
  3. 3User connected to the wrong database or with the wrong host pattern
How to reproduce
trigger — this will error
trigger — this will error
-- 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 the required privilege
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.

What not to do

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.

Sources
Official documentation ↗

MySQL 8.0 — 1142 ER_TABLEACCESS_DENIED_ERROR

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors