MySQL error 1146 (Table Doesn't Exist) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.
Verify the schema context: `SELECT DATABASE();` — if NULL, run `USE dbname;` or prefix tables with dbname.. If that does not apply, list tables to confirm the exact name: `SHOW TABLES;` or `SHOW TABLES FROM dbname LIKE '%pattern%';` — the full checklist is below.
MySQL Error Code: 1146
Official name: Table Doesn't Exist
Service: MySQL
Table '%s.%s' doesn't exist
SELECT DATABASE();
SHOW TABLES;
SELECT * FROM dbname.users LIMIT 1; -- fully qualified
Confirms which database is active and whether the table exists under its real name.
Log the failing table from err.sql and include the schema in the query to avoid cross-db mistakes.
pool.query('SELECT * FROM users WHERE id = ?', [id], (err, rows) => {
if (err && err.code === 'ER_NO_SUCH_TABLE') console.error(err.sql)
})
If a test run creates tables, make sure create_all / migrations run before queries.
Base.metadata.create_all(engine)
# or run migrations: alembic upgrade head
Always qualify the database in the DSN so PDO never lands in the wrong schema.
$pdo = new PDO('mysql:host=' . $host . ';dbname=' . $db, $user, $pass);
$pdo->exec('USE ' . $db);
Most often this happens when a typo in the table name, or wrong database selected (no `USE db` / no db prefix in the query), or when case mismatch: table names are case-sensitive on Linux depending on lower_case_table_names.
Verify the schema context: `SELECT DATABASE();` — if NULL, run `USE dbname;` or prefix tables with dbname..
This page documents fixes for: nodejs-mysql2, python-sqlalchemy, php-pdo.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official MySQL documentation linked below and adds practical troubleshooting guidance on top.