MySQL 8.4Lab-verified · 2026-11-30

MySQL ERROR 1051 (42S02): Unknown table

DROP TABLE named a table that does not exist as a base table in the database shown in the message.

MySQL 8.4.13
1051 (42S02): Unknown table 'lab_a.order_tmp'

Jump to a cause

  1. 01The table was already dropped (or never created)
  2. 02One of the tables in a multi-table DROP TABLE does not exist
  3. 03The object is a view, not a table

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-30 · container image mysql:8.4

Error 1051 comes from DROP TABLE. The message names the table as database.table, for example Unknown table 'lab_a.order_tmp', so you can see which database MySQL looked in.

In MySQL 8.4 a DROP TABLE that lists several tables is all-or-nothing: if one name is unknown, none of the tables are dropped. A view is not a table here either, so DROP TABLE on a view also gives 1051.

01The table was already dropped (or never created)

Typical when a setup or migration script runs a second time. order_tmp was dropped earlier, so the next DROP TABLE order_tmp fails. SHOW TABLES LIKE 'order%' shows only orders is left.

Setup
Setuprun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, amount INT);
CREATE TABLE order_tmp (id INT PRIMARY KEY);
DROP TABLE order_tmp;
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.01 sec)
Reproducerun as lab_a
DROP TABLE order_tmp;
✕ ERROR
ERROR 1051 (42S02): Unknown table 'lab_a.order_tmp'
Check the causerun as lab_a
SHOW TABLES LIKE 'order%';
OUTPUT
+--------------------------+
| Tables_in_lab_a (order%) |
+--------------------------+
| orders                   |
+--------------------------+
1 row in set (0.00 sec)
Checkrun as lab_a
SELECT DATABASE();
OUTPUT
+------------+
| DATABASE() |
+------------+
| lab_a      |
+------------+
1 row in set (0.00 sec)

DROP TABLE IF EXISTS does not fail. It finishes with 1 warning, and SHOW WARNINGS shows the same 1051 as a Note.

After the fixrun as lab_a
DROP TABLE IF EXISTS order_tmp;
SHOW WARNINGS;
✓ SUCCESS
Query OK, 0 rows affected, 1 warning (0.00 sec)

+-------+------+---------------------------------+
| Level | Code | Message                         |
+-------+------+---------------------------------+
| Note  | 1051 | Unknown table 'lab_a.order_tmp' |
+-------+------+---------------------------------+
1 row in set (0.00 sec)

02One of the tables in a multi-table DROP TABLE does not exist

DROP TABLE tmp_a, tmp_b, tmp_c failed on tmp_c. Right after the error, SHOW TABLES LIKE 'tmp%' still lists tmp_a and tmp_b: nothing was dropped, not even the tables that existed.

Setup
Setuprun as lab_a
CREATE TABLE tmp_a (id INT PRIMARY KEY);
CREATE TABLE tmp_b (id INT PRIMARY KEY);
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)
Reproducerun as lab_a
DROP TABLE tmp_a, tmp_b, tmp_c;
✕ ERROR
ERROR 1051 (42S02): Unknown table 'lab_a.tmp_c'
Check the causerun as lab_a
SHOW TABLES LIKE 'tmp%';
OUTPUT
+------------------------+
| Tables_in_lab_a (tmp%) |
+------------------------+
| tmp_a                  |
| tmp_b                  |
+------------------------+
2 rows in set (0.00 sec)
Checkrun as lab_a
SHOW TABLES LIKE 'tmp%';
OUTPUT
+------------------------+
| Tables_in_lab_a (tmp%) |
+------------------------+
| tmp_a                  |
| tmp_b                  |
+------------------------+
2 rows in set (0.00 sec)

With IF EXISTS the existing tables are dropped and the missing one only adds a warning. Afterwards SHOW TABLES LIKE 'tmp%' returns Empty set.

After the fixrun as lab_a
DROP TABLE IF EXISTS tmp_a, tmp_b, tmp_c;
SHOW TABLES LIKE 'tmp%';
✓ SUCCESS
Query OK, 0 rows affected, 1 warning (0.02 sec)

Empty set (0.00 sec)

03The object is a view, not a table

v_orders is a view. information_schema.tables shows it with TABLE_TYPE = VIEW. DROP TABLE only drops base tables, so it reports the view as an unknown table.

Setup
Setuprun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, amount INT);
CREATE VIEW v_orders AS SELECT id, amount FROM orders WHERE amount > 0;
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)
Reproducerun as lab_a
DROP TABLE v_orders;
✕ ERROR
ERROR 1051 (42S02): Unknown table 'lab_a.v_orders'
Check the causerun as lab_a
SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'v_orders';
OUTPUT
+------------+------------+
| TABLE_NAME | TABLE_TYPE |
+------------+------------+
| v_orders   | VIEW       |
+------------+------------+
1 row in set (0.00 sec)
Checkrun as lab_a
SHOW FULL TABLES WHERE Table_type = 'VIEW';
OUTPUT
+-----------------+------------+
| Tables_in_lab_a | Table_type |
+-----------------+------------+
| v_orders        | VIEW       |
+-----------------+------------+
1 row in set (0.00 sec)

Use DROP VIEW. The base table orders stays.

After the fixrun as lab_a
DROP VIEW v_orders;
SHOW FULL TABLES;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

+-----------------+------------+
| Tables_in_lab_a | Table_type |
+-----------------+------------+
| orders          | BASE TABLE |
+-----------------+------------+
1 row in set (0.00 sec)

FAQ

How do I fix MySQL error 1051 Unknown table?

Check the database.table name in the message with SHOW TABLES. If the table may already be gone, use DROP TABLE IF EXISTS. If it is a view, use DROP VIEW.

Does DROP TABLE drop the other tables when one of them is unknown?

No. In our MySQL 8.4 test, DROP TABLE tmp_a, tmp_b, tmp_c with a missing tmp_c dropped nothing; tmp_a and tmp_b were still there. Add IF EXISTS or remove the missing name.

Why does DROP TABLE IF EXISTS show a warning?

The missing table is reported as a Note with code 1051 instead of an error. You can see it with SHOW WARNINGS. The statement itself succeeds.

What is the difference between error 1051 and 1146?

Both use SQLSTATE 42S02. 1051 Unknown table comes from DROP TABLE; 1146 Table doesn't exist comes from queries and DML such as SELECT or INSERT.

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