MySQL 8.4Lab-verified · 2026-12-01

MySQL ERROR 1146 (42S02): Table doesn't exist

MySQL looked for the table in the database shown in the message and did not find a table with exactly that name.

MySQL 8.4.13
1146 (42S02): Table 'lab_a.customer' doesn't exist

Jump to a cause

  1. 01The table name is misspelled or the table was never created
  2. 02Table name case differs (Linux, lower_case_table_names = 0)
  3. 03The table is in a different database from the connection's default
  4. 04A trigger writes to a log table that was dropped (the message names a different table)
  5. 05A temporary table created in another connection (CREATE TEMPORARY TABLE)

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-12-01 · container image mysql:8.4

The message always names the table as database.table, for example Table 'lab_a.customer' doesn't exist. That first part is the database MySQL searched, which is usually the current default database of the connection. Read both halves: the table name may be wrong, or the name may be right and the database wrong.

On Linux, MySQL table names are case-sensitive by default, so Orders and orders are different tables. Compare the name in the message with SHOW TABLES before changing anything.

01The table name is misspelled or the table was never created

The most common case. The real table is customers, but the query says customer. SHOW TABLES LIKE 'customer%' lists what actually exists with a similar name.

Setup
Setuprun as lab_a
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(50));
INSERT INTO customers VALUES (1, 'Kim'), (2, 'Lee');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT COUNT(*) FROM customer;
✕ ERROR
ERROR 1146 (42S02): Table 'lab_a.customer' doesn't exist
Checkrun as lab_a
SHOW TABLES LIKE 'customer%';
OUTPUT
+-----------------------------+
| Tables_in_lab_a (customer%) |
+-----------------------------+
| customers                   |
+-----------------------------+
1 row in set (0.00 sec)
After the fixrun as lab_a
SELECT COUNT(*) FROM customers;
✓ SUCCESS
+----------+
| COUNT(*) |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

02Table name case differs (Linux, lower_case_table_names = 0)

The table was created as Orders and the query uses orders. On this server @@lower_case_table_names is 0, so names are stored and compared exactly as written. The same query works on Windows or macOS (where the default is 1 or 2), which is why this often shows up only after moving an app or a dump to a Linux server.

Setup
Setuprun as lab_a
CREATE TABLE Orders (id INT PRIMARY KEY, amount DECIMAL(10,2));
INSERT INTO Orders VALUES (1, 100.00);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.00 sec)
Reproducerun as lab_a
SELECT * FROM orders;
✕ ERROR
ERROR 1146 (42S02): Table 'lab_a.orders' doesn't exist
Checkrun as lab_a
SELECT @@lower_case_table_names;
SHOW TABLES;
OUTPUT
+--------------------------+
| @@lower_case_table_names |
+--------------------------+
|                        0 |
+--------------------------+
1 row in set (0.00 sec)

+-----------------+
| Tables_in_lab_a |
+-----------------+
| Orders          |
+-----------------+
1 row in set (0.00 sec)

Use the exact case shown by SHOW TABLES. lower_case_table_names can only be set when the data directory is initialized, so changing it on an existing server is not a quick fix.

After the fixrun as lab_a
SELECT * FROM Orders;
✓ SUCCESS
+----+--------+
| id | amount |
+----+--------+
|  1 | 100.00 |
+----+--------+
1 row in set (0.00 sec)

03The table is in a different database from the connection's default

The table is shop.products, but the connection's default database is lab_a. An unqualified products is looked up only in lab_a, so the message says Table 'lab_a.products' doesn't exist. SELECT DATABASE() shows the current database and information_schema.tables shows where the table really is.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE TABLE shop.products (id INT PRIMARY KEY, name VARCHAR(50));
INSERT INTO shop.products VALUES (1, 'Pen');
GRANT SELECT ON shop.* TO lab_a;
OUTPUT
Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)
Reproducerun as lab_a
SELECT * FROM products;
✕ ERROR
ERROR 1146 (42S02): Table 'lab_a.products' doesn't exist
Checkrun as lab_a
SELECT DATABASE();
SELECT table_schema, table_name FROM information_schema.tables WHERE table_name = 'products';
OUTPUT
+------------+
| DATABASE() |
+------------+
| lab_a      |
+------------+
1 row in set (0.00 sec)

+--------------+------------+
| TABLE_SCHEMA | TABLE_NAME |
+--------------+------------+
| shop         | products   |
+--------------+------------+
1 row in set (0.00 sec)

Qualify the name as shop.products, or switch with USE shop; (or set the right database in the connection string) if the whole session should work there.

After the fixrun as lab_a
SELECT * FROM shop.products;
✓ SUCCESS
+----+------+
| id | name |
+----+------+
|  1 | Pen  |
+----+------+
1 row in set (0.00 sec)

04A trigger writes to a log table that was dropped (the message names a different table)

The INSERT was into orders, but the message says Table 'lab_a.order_log' doesn't exist. An AFTER INSERT trigger on orders writes to order_log, and that table had been dropped during a cleanup. When the trigger fails, the original INSERT fails with it.

Setup
Setuprun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, amount INT);
CREATE TABLE order_log (order_id INT, logged_at DATETIME);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.01 sec)
Setuprun as root
CREATE TRIGGER lab_a.trg_orders_ai AFTER INSERT ON lab_a.orders
FOR EACH ROW INSERT INTO order_log VALUES (NEW.id, NOW());
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Setuprun as lab_a
DROP TABLE order_log;
OUTPUT
Query OK, 0 rows affected (0.01 sec)
Reproducerun as lab_a
INSERT INTO orders VALUES (1, 5000);
✕ ERROR
ERROR 1146 (42S02): Table 'lab_a.order_log' doesn't exist
Check the causerun as lab_a
SELECT trigger_name, event_manipulation, action_statement
FROM information_schema.triggers
WHERE event_object_table = 'orders';
OUTPUT
+---------------+--------------------+----------------------------------------------+
| TRIGGER_NAME  | EVENT_MANIPULATION | ACTION_STATEMENT                             |
+---------------+--------------------+----------------------------------------------+
| trg_orders_ai | INSERT             | INSERT INTO order_log VALUES (NEW.id, NOW()) |
+---------------+--------------------+----------------------------------------------+
1 row in set (0.00 sec)

information_schema.triggers lists trg_orders_ai on orders, and its ACTION_STATEMENT is INSERT INTO order_log .... That is where the table in the message comes from.

Fixrun as lab_a
CREATE TABLE order_log (order_id INT, logged_at DATETIME);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Recreating order_log made the same INSERT succeed (1 row affected) and order 1 was logged. If the log is no longer needed, drop the trigger (DROP TRIGGER) rather than leave it pointing at nothing.

After the fixrun as lab_a
INSERT INTO orders VALUES (1, 5000);
SELECT order_id FROM order_log;
✓ SUCCESS
Query OK, 1 row affected (0.00 sec)

+----------+
| order_id |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

05A temporary table created in another connection (CREATE TEMPORARY TABLE)

One connection created CREATE TEMPORARY TABLE tmp_report and could even query it, but SELECT * FROM tmp_report from the next connection failed with 1146. A temporary table is visible only to the connection that created it and disappears when that connection ends. A connection pool that hands out a different connection per statement hits exactly this.

Setup
Setuprun as lab_a
CREATE TEMPORARY TABLE tmp_report (dept VARCHAR(20), total INT);
INSERT INTO tmp_report VALUES ('Sales', 300), ('IT', 200);
SELECT * FROM tmp_report;
SELECT CONNECTION_ID() AS conn_id;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

+-------+-------+
| dept  | total |
+-------+-------+
| Sales |   300 |
| IT    |   200 |
+-------+-------+
2 rows in set (0.00 sec)

+---------+
| conn_id |
+---------+
|     358 |
+---------+
1 row in set (0.00 sec)
Reproducerun as lab_a
SELECT * FROM tmp_report;
✕ ERROR
ERROR 1146 (42S02): Table 'lab_a.tmp_report' doesn't exist
Check the causerun as lab_a
SELECT CONNECTION_ID() AS conn_id;
SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE();
OUTPUT
+---------+
| conn_id |
+---------+
|     363 |
+---------+
1 row in set (0.00 sec)

Empty set (0.01 sec)

conn_id is a different number from the connection that created the table, and information_schema.tables shows nothing (Empty set). Temporary tables are not listed there.

Checkrun as lab_a
SELECT CONNECTION_ID() AS conn_id;
OUTPUT
+---------+
| conn_id |
+---------+
|     364 |
+---------+
1 row in set (0.00 sec)

Even the check step got yet another conn_id: every step is a new connection. Creating, filling and querying the temporary table in one connection returned Sales 300 and IT 200. If several connections need it, use a regular table.

After the fixrun as lab_a
CREATE TEMPORARY TABLE tmp_report (dept VARCHAR(20), total INT);
INSERT INTO tmp_report VALUES ('Sales', 300), ('IT', 200);
SELECT * FROM tmp_report;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

+-------+-------+
| dept  | total |
+-------+-------+
| Sales |   300 |
| IT    |   200 |
+-------+-------+
2 rows in set (0.00 sec)

FAQ

How do I fix MySQL error 1146 Table doesn't exist?

Look at the database.table name in the message. Check it with SHOW TABLES and SELECT DATABASE(). Then fix the spelling, match the exact case, or qualify the table with its database (shop.products).

The table exists but MySQL says it doesn't exist

Usually the case is different (Linux treats Orders and orders as different tables) or you are connected to another database. The database part of the message tells you where MySQL looked.

Why does my query work on Windows but fail with 1146 on Linux?

On Linux lower_case_table_names defaults to 0, so table names are case-sensitive. On Windows the default is 1 (names are stored in lowercase and compared that way). Write table names in the exact case they were created.

What is SQLSTATE 42S02?

42S02 means base table or view not found. MySQL error 1146 is reported with this SQLSTATE.

The table I insert into exists, but 1146 names a different table

A trigger on that table probably writes to the other table. Look for the table name in ACTION_STATEMENT of information_schema.triggers.

Why does my TEMPORARY TABLE say doesn't exist?

A temporary table is visible only to the connection that created it. Querying it from another connection (for example through a pool) gives 1146. Create and use it in the same connection.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13