MySQL Error 1142: Command Denied for Table
Fix MySQL Error 1142 by identifying the authenticated account, checking active roles, and granting only the required table privilege.
On this page
MySQL Error 1142 (42000, ER_TABLEACCESS_DENIED_ERROR) means the connected account lacks a privilege for the named command and table. The message identifies the command, account, and table, for example SELECT command denied to user ... for table .... The server has accepted the connection; this is a request-authorization failure, not a password error. See the MySQL 8.4 error reference.
Check which account and roles the session uses
Run these statements in the same connection that failed:
SELECT USER() AS connection_identity,
CURRENT_USER() AS privilege_account;
SHOW GRANTS FOR CURRENT_USER;
USER() reports the identity supplied by the client; CURRENT_USER() reports the account whose privileges MySQL checks. They can differ if a different or anonymous account matched the connection. See MySQL’s connection verification guidance and CURRENT_USER() reference.
If the account uses roles on MySQL 8.0 or later, confirm that the needed role is active in this session:
SELECT CURRENT_ROLE();
MySQL 5.7 does not support roles, so skip this check there. SHOW GRANTS FOR CURRENT_USER lists the account’s grants and assigned roles; inspect a role’s privileges with SHOW GRANTS FOR CURRENT_USER USING 'role_name'. A role that is assigned but inactive does not provide its privileges to the current session. See MySQL 8.0 roles, information functions, and SHOW GRANTS.
Grant only the required table privilege
Ask an administrator or an account authorized to grant privileges to match the rejected command to the minimum needed privilege. For example, if report_reader needs to read one table, grant SELECT on that table to the exact account shown by CURRENT_USER():
GRANT SELECT
ON `app_db`.`orders`
TO 'report_reader'@'localhost';
Replace the example schema, table, user, and host with the real values. Use INSERT, UPDATE, DELETE, or another privilege only when the failed operation requires it. A database-level grant such as ON app_db.* affects more objects than a grant on one table; avoid GRANT ALL ON *.* as a routine fix. See MySQL’s table-level GRANT syntax and the SQLiz GRANT guide.
If the GRANT statement is itself denied, the current account cannot delegate that privilege; ask a database administrator to apply the least-privilege grant. Do not edit MySQL grant tables directly.
Distinguish related access errors
- Error 1142 (
42000): a command is denied for a named table. Check the privilege for that operation at the correct scope. - Error 1143 (
42000): access to a specific column is denied; the error names the column. See Error 1143 troubleshooting. - Error 1044 (
42000): the account lacks access to the named database; see Error 1044 troubleshooting. - Error 1045 (
28000): MySQL rejected the account during connection authentication; see Error 1045 troubleshooting.
For more codes, browse MySQL Error Troubleshooting.