ERROR database schema_error ai_generated true

ERROR 1146 (42S02): Table 'mydb.my_table' doesn't exist

ID: database/mysql-table-doesnt-exist

Also available as: JSON · Markdown
91%Fix Rate
93%Confidence
60Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active

Root Cause

The referenced table does not exist in the specified database. Common causes include missing migrations, connecting to the wrong database, case sensitivity issues on Linux (MySQL table names are case-sensitive on case-sensitive filesystems), or InnoDB tablespace corruption.

generic

Workarounds

  1. 92% success Run pending migrations to create the missing table
    Run the application's migration tool (e.g., 'php artisan migrate', 'npx sequelize db:migrate', 'rails db:migrate'). Verify the table exists: SHOW TABLES LIKE 'my_table';
  2. 85% success Check the database name and table name case sensitivity
    On Linux, MySQL table names are case-sensitive. Run: SHOW TABLES; to list actual table names. Verify you are in the correct database: SELECT DATABASE(); Use the exact case in queries. If developing cross-platform, set lower_case_table_names=1 at initialization time.

Dead Ends

Common approaches that don't work:

  1. Changing lower_case_table_names after the database has been initialized 90% fail

    lower_case_table_names must be set before MySQL data directory initialization. Changing it on an existing instance with mixed-case table names causes existing tables to become inaccessible.

  2. Copying .ibd tablespace files from another MySQL instance directly 88% fail

    InnoDB tablespace files are tied to the specific MySQL instance's data dictionary. Simply copying .ibd files without proper IMPORT TABLESPACE procedure causes corruption errors.

Error Chain

Leads to:
Preceded by:
Frequently confused with: