errorMySQLError 1146

MySQL Error 1146: Table Doesn't Exist

Error Message
ERROR 1146 (42S02): Table 'myapp.user_sessions' doesn't exist

What is MySQL Error 1146?

MySQL Error 1146 occurs when a SQL statement references a table that does not exist in the current database. This is commonly caused by typos, wrong database selection, or missing database migrations.

Common Causes

  • 1

    Typo in the table name

  • 2

    Connected to the wrong database (USE wrong_database)

  • 3

    Table was deleted or never created (missing migration)

  • 4

    Case sensitivity issue on Linux — MySQL on Linux is case-sensitive by default

  • 5

    Table exists in a different schema/database than referenced

  • 6

    Temporary table expired (only exists for the session duration)

Step-by-Step Solutions

1

Verify the table exists: SHOW TABLES LIKE 'table_name';

2

Verify the correct database: SELECT DATABASE(); and USE correct_database;

3

Check for case sensitivity: SHOW TABLES; (exact casing must match on Linux)

4

Run pending database migrations if this is an application table

5

Check if table name has a typo: SHOW TABLES; lists all available tables

Prevention Tips

  • Always run database migrations before deploying application code

  • Use CI/CD pipeline checks to verify database schema before deployment

  • On Linux MySQL servers, set lower_case_table_names=1 to avoid case sensitivity issues

  • Use schema version management tools (Flyway, Liquibase) to track table creation

Frequently Asked Questions

Why is MySQL Error 1146 case-sensitive on Linux?
MySQL on Linux stores tables as files in the filesystem, which is case-sensitive by default. 'Users' and 'users' are different tables on Linux but the same on Windows. Set lower_case_table_names = 1 in my.cnf to make MySQL case-insensitive on Linux, or always use consistent casing.
How do I check if a MySQL table exists?
SHOW TABLES LIKE 'table_name'; — shows the table if it exists. Or: SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'your_db' AND table_name = 'your_table'; Returns 1 if table exists, 0 if not.

Related Errors

Still Stuck?

Ask our AI SQL Assistant or the community — get answers in seconds.