1049ERRORTier 1 — Safe✅ HIGH confidence

Unknown database

Category: SchemaVersions: All MariaDB / MySQL versions

What this means

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.

Why it happens

  1. 1The database was not created before the application started
  2. 2The database name in the connection string has a typo
  3. 3The database was created on a different server or environment
  4. 4The database was accidentally dropped

How to reproduce

A USE statement references a database that does not exist.

trigger — this will ERROR
USE myapp_production;
ERROR 1049 (42000): Unknown database 'myapp_production'

Fix 1: Create the database

When the database should exist but was never created.

fix
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 the database exists but the name may be wrong.

fix
SHOW DATABASES;

Why this works

SHOW DATABASES lists all databases the current user has access to, allowing the correct name to be confirmed.

What not to do

Create an empty database in production without running migrations

Why it's wrong: An empty database will cause further errors when the application attempts to query non-existent tables. Always run schema migrations after creating the database.

Version notes

All versionsMariaDB database names are case-sensitive on case-sensitive filesystems (Linux) and case-insensitive on case-insensitive filesystems (Windows, macOS).

Sources

📚 Official docs: https://mariadb.com/kb/en/create-database/

🔧 Source ref: MariaDB Server error code 1049 / ER_BAD_DB_ERROR

📖 Further reading: MariaDB CREATE DATABASE

Confidence assessment

✅ HIGH confidence

Stable.

See also

📄 Reference pages

CREATE DATABASESHOW DATABASES
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →