MySQL error 1146: Table doesn't exist
MySQL can't find the table in the named or current database. Check the database, the spelling and, on Linux, the letter case of the name.
- Error number
1146- Name
ER_NO_SUCH_TABLE- SQLSTATE
42S02- Category
- Databases, tables and columns
What it means
The message shows the database and table MySQL looked for: Table 'shop.orders' doesn't exist. That tells you which database it searched, which is often the real problem.
Whether table names are case-sensitive depends on lower_case_table_names: by default they are on Linux and not on Windows or macOS, so code that works on a laptop can fail with 1146 on a Linux server.
Common causes
- Connected to a different database than the one holding the table.
- A typo, or a different letter case on a Linux server.
- The table hasn't been created yet: a migration didn't run, or a restore is incomplete.
- An InnoDB table whose data dictionary entry exists but whose
.ibdfile is missing or damaged (the server error log will say so).
How to fix it
-
Check which database you're in and what tables it has.
SELECT DATABASE(); SHOW TABLES LIKE '%order%';
-
Search every database for the table.
SELECT table_schema, table_name FROM information_schema.tables WHERE LOWER(table_name) = 'orders';
-
Qualify the name with the database, or
USEthe right one.SELECT * FROM shop.orders LIMIT 10;
Reproduce it safely
SELECT * FROM no_such_table; -- ERROR 1146 (42S02): Table 'db.no_such_table' doesn't exist
Related errors
1049Unknown database1046No database selected1054Unknown column in field list1051Unknown table208SQL Server: Invalid object name42P01PostgreSQL: relation does not existORA-00942Oracle: table or view does not exist
More databases, tables and columns errors
1050Table already exists1060Duplicate column name1091Can't DROP; check that column/key exists1305Function or procedure does not exist1442Trigger can't update its own table
The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.
Work on MySQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.