Error codes › 1049
MySQL & MariaDB error 1049: Unknown database
Example from our test runs:
Unknown database 'no_such_db' (5.6.51) The database named in USE, the connection string or a qualified name doesn't exist on this server. Usually a typo, letter case, or the wrong server.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_BAD_DB_ERROR | ER_BAD_DB_ERROR |
| SQLSTATE | 42000 | 42000 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
Unknown database 'shop_prod' means the server has no schema of that name, or none that this account can see. The error comes from USE, from the database part of a connection, or from CREATE TABLE/SELECT with db.table names.
Why it happens
- A typo, or a name that is different on this environment (
shopin development,shop_prodin production). - Letter case: database names are directory names, so with
lower_case_table_names = 0(the Linux default)Shopandshopare different databases. - The client connected to a different server or port than you think: a local test server instead of the container, or a replica that hasn’t got the database yet.
- The import that should have created it hasn’t run, or the dump didn’t include
CREATE DATABASE(dumps made without--databasesdon’t). - An account with no privileges at all on a database may get 1044 “Access denied” instead, so 1049 really does mean the database isn’t there.
How to fix it
SHOW DATABASES;orSELECT schema_name FROM information_schema.SCHEMATA;lists what exists. CheckSELECT @@hostname, @@port;to confirm which server you are on.- Create it if it should exist:
CREATE DATABASE shop CHARACTER SET utf8mb4;, then rerun the import. - In scripts,
CREATE DATABASE IF NOT EXISTS shop;beforeUSE shop;makes them repeatable.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database:CREATE DATABASE demo; USE demo;Run:
USE no_such_db;
You get: Unknown database 'no_such_db'(11.8.9)
Verified fixes
List the databases you can see, then use the exact name
SELECT schema_name FROM information_schema.SCHEMATA WHERE schema_name = DATABASE();
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| USE a database that doesn't exist (or is spelled differently) repro | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 |
| The same mistake in a connection string or on the mysql command line version check | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 | ✓ 1049 |
| List the databases you can see, then use the exact name fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
USE a database that doesn't exist (or is spelled differently) repro
MySQL 5.6✓ 10495.7✓ 10498.0✓ 10498.4✓ 10499✓ 1049
MariaDB 10.6✓ 104910.11✓ 104911.4✓ 104911.8✓ 1049
The same mistake in a connection string or on the mysql command line version check
MySQL 5.6✓ 10495.7✓ 10498.0✓ 10498.4✓ 10499✓ 1049
MariaDB 10.6✓ 104910.11✓ 104911.4✓ 104911.8✓ 1049
List the databases you can see, then use the exact name fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9