mysqldude
Error codes › 1049

MySQL & MariaDB error 1049: Unknown database

Error messageUnknown 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.

MySQLMariaDB
SymbolER_BAD_DB_ERRORER_BAD_DB_ERROR
SQLSTATE4200042000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery 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 (shop in development, shop_prod in production).
  • Letter case: database names are directory names, so with lower_case_table_names = 0 (the Linux default) Shop and shop are 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 --databases don’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; or SELECT schema_name FROM information_schema.SCHEMATA; lists what exists. Check SELECT @@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; before USE shop; makes them repeatable.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database:

    CREATE DATABASE demo;
    USE demo;
  2. Run:

    USE no_such_db;

You get: Unknown database 'no_such_db'(11.8.9)

Verified fixes

  1. List the databases you can see, then use the exact name

    SELECT schema_name FROM information_schema.SCHEMATA WHERE schema_name = DATABASE();

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.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

Related errors

  • 1046 ER_NO_DB_ERRORexplained
  • 1146 ER_NO_SUCH_TABLEexplained
  • 1044 ER_DBACCESS_DENIED_ERRORexplained