Skip to content
ERROR 1146 (42S02): Table 'database.table' doesn't exist

ERROR 1146 (42S02): Table 'database.table' doesn't exist

DodaTech 2 min read

The error “ERROR 1146 (42S02): Table ‘database.table’ doesn’t exist” means MySQL could not find a table with the specified name in the given database.

What It Means

MySQL’s storage engine searched for the table in the table metadata. The table name either does not exist in the specified database, the database itself does not exist, or the table name was used in a context that resolved to the wrong location.

Why It Happens

  • The table was never created.
  • You connected to the wrong database — the table exists in db1 but you are querying in db2.
  • The table name is case-sensitive on case-sensitive file systems (Linux) — Users is different from users.
  • The table was accidentally dropped or the database was recreated without restoring.
  • A migration or schema script failed partway through, leaving the database without some tables.
  • The table exists but you are not using the fully qualified name and the default database is wrong.

How to Fix It

1. List tables in the current database

USE database_name;
SHOW TABLES;

2. Check for the table using a fully qualified name

SELECT * FROM database_name.table_name LIMIT 1;

3. Check the database name and connection

mysql -u user -p -D database_name
SHOW DATABASES;

4. Recreate the table from schema

SOURCE /path/to/schema.sql;

5. Restore from backup

mysql -u user -p database_name < backup.sql

FAQ

Is MySQL table name case-sensitive?
On Linux, MySQL table names are case-sensitive because the filesystem is case-sensitive. On Windows and macOS, they are case-insensitive. Set lower_case_table_names=1 in my.cnf to make all table names case-insensitive.
How do I check if a specific table exists without an error?
Run SHOW TABLES LIKE 'table_name'; or SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'db' AND table_name = 'table_name';.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro