Menu

MySQL Error 1146: Table Doesn't Exist (42S02)

Fix MySQL Error 1146 (42S02) by checking the selected database, exact table name and case, and whether the table migration ran.

Posted on By
On this page

MySQL Error 1146 (42S02, ER_NO_SUCH_TABLE) means a statement referenced a table that MySQL could not find in the database it searched. A typical message is:

ERROR 1146 (42S02): Table 'app_db.orders' doesn't exist

The MySQL 8.4 error reference lists this error. MySQL’s troubleshooting guide for missing tables notes that the table may be absent from the default database, or may exist under a name you are referencing incorrectly.

Check which database the connection selected

For an unqualified table name such as orders, MySQL looks in the connection’s current database. Check it first:

SELECT DATABASE();
SHOW TABLES FROM `app_db`;

For more ways to list tables, see the MySQL SHOW TABLES tutorial.

If DATABASE() returns a different database or NULL, select the intended database before rerunning the query:

USE `app_db`;
SELECT * FROM `orders`;

For a one-off query, qualify the table with its database instead:

SELECT * FROM `app_db`.`orders`;

See Error 1046: no database selected and the MySQL USE tutorial if the connection has no default database.

Verify the exact table name and letter case

Compare the table name in the statement with the output from SHOW TABLES FROM app_db. Database and table-name case sensitivity depends on the server’s platform and lower_case_table_names setting. Use consistent spelling and letter case; see MySQL’s identifier case-sensitivity rules.

Also confirm the database name used by the application. Development, test, and production servers may have different schemas. If the table exists in another database, either select the correct database or qualify it in the statement.

If you cannot see the table in SHOW TABLES, your account may lack privileges to list or access it. Ask an administrator to confirm the table and your grants before concluding it does not exist.

Check the migration or restore step

If the table should exist in this database, check that the schema migration, import, or application setup ran successfully against this server. Creating an empty replacement table may silence the error but leave the application with the wrong columns, indexes, or data. Compare the table definition with the expected schema and rerun the intended migration or restore procedure.

Temporary tables are visible only in the session that created them. If one connection creates a temporary table and another connection later queries it, the second session can return Error 1146. Create or query that temporary table in the same connection, or use a persistent table if it must be shared across sessions.

Do not use DROP TABLE as a routine fix for Error 1146: the reported table was not found in the searched database, and dropping other tables can destroy data. Error 1050 is the opposite case, where a table with the name already exists; see MySQL Error 1050 troubleshooting. For table creation syntax, see the MySQL CREATE TABLE tutorial.

Browse more fixes in MySQL error troubleshooting.