// MySQL error reference

MySQL error 1049: Unknown database

The database named in the connection or in a USE statement doesn't exist on this server, or its name is spelled or cased differently.

Error number
1049
Name
ER_BAD_DB_ERROR
SQLSTATE
42000
Category
Databases, tables and columns
Error message
Unknown database '%s'

What it means

MySQL couldn't find a database (schema) with that name. You get it when connecting with a default database, running USE name, or referring to name.table.

On Linux, database names are case-sensitive by default (lower_case_table_names = 0) because each database is a directory, so Shop and shop are different databases there but not on Windows or macOS.

Common causes

  • A typo or different case in the database name.
  • Connecting to the wrong server or port, for example a fresh local instance instead of the one with your data.
  • The database was never created, or a restore or migration hasn't run yet.
  • A connection string that passes the database name with quotes or extra spaces.

How to fix it

  1. List the databases this account can see.

    SHOW DATABASES;
  2. Create it if it should exist.

    CREATE DATABASE shop CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
  3. Check which server you're connected to.

    SELECT @@hostname, @@port, VERSION();

Reproduce it safely

USE no_such_database;  -- ERROR 1049 (42000): Unknown database 'no_such_database'

Related errors

More databases, tables and columns errors

The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.

// fewer errors, faster fixes

Work on MySQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.