MySQL & MariaDB error 1146: Table doesn't exist
Table 't_2.t1 WHERE 0 UNION SELECT s FROM secret' doesn't exist (5.6.51) The statement names a table the server can't find in that database. A typo, the wrong database, letter case on Linux, or a table that really is missing (or whose files are damaged).
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_NO_SUCH_TABLE | ER_NO_SUCH_TABLE |
| SQLSTATE | 42S02 | 42S02 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
The message gives the fully qualified name the server looked for: Table 'shop.order_items' doesn't exist. Check both halves: the table name and the database it was looked up in.
Why it happens
- A typo, or the table is in another database (no
USE, or the connection string names a different schema). - Letter case: on Linux the default
lower_case_table_names = 0makes table names case-sensitive, soOrdersandordersare different tables. Code written on Windows or macOS (case-insensitive) breaks when moved to Linux. - The table was never created: a migration didn’t run, or a
CREATEfailed earlier in a script. - After copying data files by hand, InnoDB may know the table in its dictionary but not have the
.ibdfile, or the reverse. That also shows as 1146 (sometimes with 1932 “doesn’t exist in engine”).
How to fix it
SHOW TABLES;orSELECT table_schema, table_name FROM information_schema.TABLES WHERE table_name LIKE '%order%';to find the real name and database.- Use the exact case, or qualify the name:
SELECT … FROM shop.Orders. lower_case_table_namescan only be set when the data directory is initialised on MySQL 8.0, so pick it before creating databases if you need case-insensitive names on Linux.- For a table damaged by file copies, restore it from a logical backup (mysqldump) rather than copying files.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE Orders (id INT);Run:
SELECT * FROM order_items;
You get: Table 't_0.order_items' doesn't exist(11.8.9)
Verified fixes
List the tables and use the exact name, or qualify it with the database
SELECT table_name FROM information_schema.TABLES WHERE table_schema = DATABASE();
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| Query a table that isn't in the current database repro | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 |
| Same name, different letter case (lower_case_table_names=0 on Linux) version check | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 | ✓ 1146 |
| List the tables and use the exact name, or qualify it with the database fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Related errors
Where this error shows up in our guides
- Writing dynamic SQL in stored procedures · Quote the identifier with backticks; injection attempt now fails (1146) MySQL 5.6 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
- Splitting fields · SELECT from tdata before calling the procedure (expect 1146) MySQL 5.6 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8