mysqldude
Error codes › 1142

MySQL & MariaDB error 1142: Command denied to user for table

MySQL… command denied to user '…'@'…' for table '…'
MariaDB… command denied to user '…'@'…' for table ….…
Example from our test runs: SELECT command denied to user 'appuser'@'127.0.0.1' for table 'salaries' (5.6.51) · SELECT command denied to user 'appuser'@'127.0.0.1' for table `t_0`.`salaries` (10.6.28)

The account has no privilege for this statement on this table (for example SELECT, INSERT, DROP). The message names the command, the account and the table.

MySQLMariaDB
SymbolER_TABLEACCESS_DENIED_ERRORER_TABLEACCESS_DENIED_ERROR
SQLSTATE4200042000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

SELECT command denied to user 'appuser'@'10.0.0.5' for table 'salaries'. Privileges are checked per account (user plus host) at global, database, table and column level. This account has none that allow this command on this table.

Why it happens

  • The account was granted privileges on specific tables, and the query touches another one, including through a view, a JOIN or a stored routine.
  • A grant was made for a different host than the one the application connects from ('app'@'localhost' vs 'app'@'%'); check SELECT CURRENT_USER();.
  • Missing privileges for administrative commands: DROP, ALTER, TRIGGER, REFERENCES (for foreign keys), LOCK TABLES (mysqldump), SHOW VIEW.
  • Roles (MySQL 8.0, MariaDB 10.0.5+) that are granted but not active: SET DEFAULT ROLE was never run.

How to fix it

  • Check what the account has: SHOW GRANTS FOR 'appuser'@'%';
  • Grant what is needed, as narrowly as possible: GRANT SELECT ON shop.salaries TO 'appuser'@'%'; or a database-wide GRANT SELECT, INSERT, UPDATE, DELETE ON shop.* TO ….
  • For roles: SET DEFAULT ROLE ALL TO 'appuser'@'%';

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database and the test data:

    CREATE DATABASE demo;
    USE demo;
    CREATE TABLE salaries (id INT, amount INT);
    CREATE TABLE public_info (id INT);
  2. Run:

    CREATE USER 'appuser'@'%' IDENTIFIED BY 'Test#1234';
    GRANT SELECT ON demo.public_info TO 'appuser'@'%';
  3. In a shell on the database host:

    mysql -uappuser -p'Test#1234' -h127.0.0.1 demo -e 'SELECT * FROM salaries'

You get: ERROR 1142 (42000) at line 1: SELECT command denied to user 'appuser'@'127.0.0.1' for table `t_0`.`salaries`(11.8.9)

Verified fixes

  1. Grant the privilege on that table (or the whole database)

    CREATE USER 'appuser'@'%' IDENTIFIED BY 'Test#1234';
    GRANT SELECT ON demo.salaries TO 'appuser'@'%';
    mysql -uappuser -p'Test#1234' -h127.0.0.1 demo -N -e 'SELECT COUNT(*) FROM salaries'

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
A user with SELECT on one table reads another
repro
✓ 1142✓ 1142✓ 1142✓ 1142✓ 1142✓ 1142✓ 1142✓ 1142✓ 1142
Grant the privilege on that table (or the whole database)
fix
✓✓✓✓✓✓✓✓✓
A user with SELECT on one table reads another repro
MySQL 5.6✓ 11425.7✓ 11428.0✓ 11428.4✓ 11429✓ 1142
MariaDB 10.6✓ 114210.11✓ 114211.4✓ 114211.8✓ 1142
Grant the privilege on that table (or the whole database) fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

Related errors

  • 1044 ER_DBACCESS_DENIED_ERRORexplained
  • 1045 ER_ACCESS_DENIED_ERRORexplained
  • 1227 ER_SPECIFIC_ACCESS_DENIED_ERRORexplained
  • 1143 ER_COLUMNACCESS_DENIED_ERROR
How the message changed between versions
MariaDB fromSymbolMessage
5.5.68ER_TABLEACCESS_DENIED_ERROR%-.16s command denied to user '%s'@'%s' for table '%-.192s'
10.2.44ER_TABLEACCESS_DENIED_ERROR%-.100T command denied to user '%s'@'%s' for table '%-.192s'
10.3.39ER_TABLEACCESS_DENIED_ERROR%-.100T command denied to user '%s'@'%s' for table %`s.%`s
11.8.10ER_TABLEACCESS_DENIED_ERROR%-.100sT command denied to user '%s'@'%s' for table %sQ.%sQ