Unknown database
Error 1049 (SQLSTATE 42000) is returned when a USE statement or a connection string specifies a database that does not exist on the server. It is one of the most common connection-time errors in application deployment.
- 1The database was not created before the application started
- 2The database name in the connection string has a typo
- 3The database was created on a different server or environment
- 4The database was accidentally dropped
A USE statement references a database that does not exist.
USE myapp_production;
expected output
ERROR 1049 (42000): Unknown database 'myapp_production'
Fix 1
Create the database
WHEN When the database should exist but was never created.
CREATE DATABASE IF NOT EXISTS myapp_production CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Why this works
CREATE DATABASE creates the schema directory and registers the database in information_schema. IF NOT EXISTS prevents an error if it was already created by another process.
Fix 2
List existing databases to find the correct name
WHEN When the database exists but the name may be wrong.
SHOW DATABASES;
Why this works
SHOW DATABASES lists all databases the current user has access to, allowing the correct name to be confirmed.
✕ Create an empty database in production without running migrations
An empty database will cause further errors when the application attempts to query non-existent tables. Always run schema migrations after creating the database.
MariaDB database names are case-sensitive on case-sensitive filesystems (Linux) and case-insensitive on case-insensitive filesystems (Windows, macOS).
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev