MySQL Schema

MySQL Error 1146: Table Doesn't Exist (Fix Guide)

Fix MySQL Error 1146 table doesn't exist. Covers wrong database, case sensitivity, typos, missing migrations, and dropped tables.

Mar 12, 2026 4 min read

The Error Message

Table 'database.table' doesn't exist

What Causes MySQL 1146?

MySQL Error 1146 occurs when you reference a table that doesn't exist in the current database. This can be a typo, wrong database context, case sensitivity issue, or the table was never created.

Common Causes

Typo in table name

You wrote 'usres' instead of 'users' or 'Customers' instead of 'customers'.

Wrong database selected

You're connected to 'test' but the table is in 'production'.

Case sensitivity (Linux)

On Linux, MySQL table names are case-sensitive. Windows and macOS are case-insensitive by default.

Table was dropped or never created

A migration failed or someone dropped the table without you knowing.

How to Fix It

Step 1: Check which database you are using

Make sure you are connected to the right database before querying.

SELECT DATABASE();

-- Switch to the correct database:
USE your_database;

Step 2: List all tables

This shows all tables in your current database so you can check the exact name.

SHOW TABLES;

-- Or search for a specific table:
SHOW TABLES LIKE '%user%';

Step 3: Use fully qualified table name

Prefix the table name with the database name to avoid context issues.

-- Instead of:
SELECT * FROM users;

-- Use:
SELECT * FROM production.users;

Step 4: Create the table if missing

If the table was never created, run your migration or create it manually.

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  email VARCHAR(255) UNIQUE,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

How to Prevent This Error

Use migrations to track database schema changes. Always specify the database name in connection strings. On Linux, use lowercase table names consistently.

Fix MySQL Errors with AI2SQL

Instead of debugging SQL syntax manually, describe what you need in plain English and let AI2SQL generate the correct query for MySQL.

Try AI2SQL Free

No credit card required

Frequently Asked Questions

Why does MySQL say 'Table 'database.table_name' doesn't exist'?

Five real causes, in order of frequency: 1) you are connected to the wrong database (run SELECT DATABASE() to check), 2) on Linux, lower_case_table_names defaults to 0 so Users and users are different tables — on macOS and Windows it defaults to 2 and is case-insensitive, 3) the table was dropped or renamed, 4) a migration never ran in this environment, 5) the .frm or .ibd file is missing from the data directory after a botched copy.

How do I check if a table exists in MySQL?

Run SHOW TABLES LIKE 'table_name'; for the current database, or query SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'table_name'; to find it across every schema. The second form is what you want when you're not sure which database the table lives in.

Why does my table exist on dev but not on production?

Almost always a migration that was applied locally but never shipped. Check your migrations directory for an unapplied file, then run the migration command for your stack (e.g., npx prisma migrate deploy, php artisan migrate, alembic upgrade head). Confirm with SELECT * FROM schema_migrations or your equivalent tracking table.

Does Linux really treat MySQL table names differently from macOS?

Yes. The lower_case_table_names server variable controls this. On Linux it defaults to 0 (case-sensitive table names). On macOS it defaults to 2 (stored as given, compared case-insensitively). On Windows it defaults to 1 (lowercased on storage). MySQL 8.0 will refuse to start if you change lower_case_table_names after initialization, so set it once during server setup.

Can AI2SQL help me recreate a missing table?

Yes. Describe the structure in plain English ('users table with id, email, created_at, with email unique') and AI2SQL emits the right CREATE TABLE for MySQL 5.7 or 8.0+ — including indexes, charset, and AUTO_INCREMENT — so you can re-run the migration without rewriting it from scratch.

Stop Debugging SQL Errors Manually

Describe what you need in plain English. AI2SQL generates correct MySQL queries instantly.

Try AI2SQL Free

No credit card required