MySQL error 1146, "Table doesn't exist", means the server found no table with that exact schema and name. The error message spells out both, Table 'db.name' doesn't exist, and that is the first thing to read carefully. In our experience the table usually does exist, just in another schema, on another server, or with different letter case.
What the error means
The error is ER_NO_SUCH_TABLE, SQLSTATE 42S02 (MySQL error reference). Several neighbouring errors mean something else, and it helps not to mix them up:
- 1046 "No database selected": you did not choose a schema at all.
- 1049 "Unknown database": the schema itself is missing.
- 1356: a view refers to a table or column that is gone, or its definer lacks rights.
mysql> SELECT * FROM Orders LIMIT 1;
ERROR 1146 (42S02): Table 'shop.Orders' doesn't exist
Step 1: confirm where you are
SELECT DATABASE(), @@hostname, @@port, @@lower_case_table_names;
-- every table with that name, in any schema and any letter case
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
FROM information_schema.TABLES
WHERE LOWER(TABLE_NAME) = LOWER('Orders');
This one query answers most tickets. If the table shows up under another TABLE_SCHEMA, the connection's default schema or the application's config is wrong. If it shows up with different letter case, read the next section. If it does not show up at all, check @@hostname and @@port: a client pointed at a replica, a staging instance or a local MySQL on 3306 will tell you the truth about the wrong server.
Cause 1: letter case and lower_case_table_names
Table names map to files, so case sensitivity depends on the file system. The defaults for lower_case_table_names are 0 on Unix, 1 on Windows and 2 on macOS. With 0, names are compared case-sensitively, so Orders and orders are different tables on Linux (identifier case sensitivity).
-- Linux, lower_case_table_names=0 (default on Unix)
CREATE TABLE Orders (id INT PRIMARY KEY);
SELECT * FROM orders; -- ERROR 1146: Table 'shop.orders' doesn't exist
SELECT * FROM Orders; -- works
The classic version: code written on a Windows or macOS laptop says orders, the table was created as Orders, and everything breaks after the first deploy to Linux. The fix is to make code and schema agree. Do not plan on flipping the setting: lower_case_table_names can only be set when the server is initialized, and changing it afterwards is prohibited (docs). If you need case-insensitive names on Linux, that means a new instance initialized with lower_case_table_names=1 and a logical dump and reload.
Cause 2: a view points to a table that is gone
Dropping or renaming a table does not drop the views built on it. Queries against the view then fail with 1356, and it is easy to misread as a missing table. CHECK TABLE on the view reports tables that its definition refers to but that no longer exist (CHECK TABLE).
mysql> SELECT * FROM v_daily_sales;
ERROR 1356 (HY000): View 'shop.v_daily_sales' references invalid table(s)
or column(s) or function(s) or definer/invoker of view lack rights to use them
CHECK TABLE v_daily_sales;
SHOW CREATE VIEW v_daily_sales\G
Cause 3: files copied into the data directory
Since MySQL 8.0, table metadata lives in a transactional data dictionary instead of metadata files (data dictionary). In our experience, a .ibd file dropped into a schema directory does not become a table, and a restore that copied only some files leaves you with 1146 or worse. To move a single InnoDB table between servers, use transportable tablespaces (importing InnoDB tables):
-- destination: same definition as the source table
CREATE TABLE t1 (...) ENGINE=InnoDB;
ALTER TABLE t1 DISCARD TABLESPACE;
-- source: keep this session open until the copy is done
FLUSH TABLES t1 FOR EXPORT;
-- copy t1.ibd and t1.cfg to the destination schema directory
UNLOCK TABLES;
-- destination
ALTER TABLE t1 IMPORT TABLESPACE;
The rules that bite in practice:
- It only works for file-per-table tablespaces.
- The page size and the server version must match.
- Tables with
FULLTEXTindexes cannot be flushed for export. - The
.ibdand.cfgfiles must be copied beforeUNLOCK TABLES, because unlocking removes the.cfg.
For whole databases, a physical backup tool or a logical dump is the safer route; see our mysqldump vs XtraBackup comparison.
Cause 4: temporary tables and connection pools
A TEMPORARY table is visible only within the session that created it and disappears when that session closes (CREATE TEMPORARY TABLE). With a connection pool, the next query may run on a different connection. In our experience, code that creates a temp table in one call and reads it in the next works on a developer's machine and fails under load with 1146.
Cause 5: the replica never created the table
On a replica, 1146 stops the SQL thread, and SHOW REPLICA STATUS shows Last_SQL_Errno: 1146. A frequent reason is database-level replication filters. With statement-based logging, replicate-do-db checks the default database set by USE. With row-based logging, it checks the database of the changed table. DDL is always logged as a statement, even with binlog_format=ROW (replication filtering rules). So a CREATE TABLE shop.x issued while another database is selected can be filtered out, while the rows that follow are applied and fail.
-- replica started with replicate-do-db=shop, source runs:
USE tools;
CREATE TABLE shop.audit_log (...); -- DDL is logged as a statement,
-- checked against "tools": skipped
INSERT INTO shop.audit_log ...; -- row event, checked against "shop":
-- applied, fails with 1146
SHOW REPLICA STATUS\G -- Last_SQL_Errno: 1146
Do not just skip the event: every later write to that table will fail the same way. Create the table on the replica with the exact definition from the source, or reseed the replica, and fix the filter or the habit that caused it. Our guide to replication error 1062 covers why skipping errors leaves a replica quietly diverged.
What changes on large systems
- Cross-platform migrations. Moving binary data between Windows and Linux is only clean if all names are lowercase. The manual recommends
lower_case_table_names=1on all platforms when you use InnoDB and want to avoid these problems (docs, moving InnoDB tables). Decide before initializing the target, because you cannot change it later. - Hundreds of schemas. Multi-tenant setups often have a schema per customer. A migration that ran on 498 of 500 schemas produces 1146 for two customers only. Compare table counts per schema in
information_schema.TABLESafter every rollout. - Replicas and filters. Filters look harmless until the first DDL with an unexpected default database. In our experience, fleets without database filters have far fewer of these incidents. If you need them, prefer table-level filters with wildcards, and require fully qualified names plus a matching
USEin migrations. - Restores. A partial restore of a large database is where missing tables show up first. After any restore, diff the table list and row-count estimates against the source before pointing applications at it.
- Monitoring. Count 1146 errors by schema and by application. A spike right after a deploy almost always means code and schema shipped out of order.
Key takeaways
- Read the schema and name in the message; check
DATABASE(),@@hostnameand@@port. - Search
information_schema.TABLESwithLOWER()to catch wrong schemas and letter case. lower_case_table_namesdefaults to 0 on Unix and can only be set at initialization.- Views over dropped tables give 1356; find them with
CHECK TABLE. - Do not copy
.ibdfiles by hand: use transportable tablespaces or a proper backup tool. - On replicas, check database filters and recreate the table instead of skipping events.