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
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
-
List the databases this account can see.
SHOW DATABASES;
-
Create it if it should exist.
CREATE DATABASE shop CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
-
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
1046No database selected1044Access denied for user to database1146Table doesn't exist4060SQL Server: Cannot open database requested3D000PostgreSQL: database does not exist
More databases, tables and columns errors
1054Unknown column in field list1050Table already exists1051Unknown table1060Duplicate column name1091Can't DROP; check that column/key exists1305Function or procedure does not exist1442Trigger can't update its own table
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.
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.