1049
MariaDBERRORCommonSchemaHIGH confidence

Unknown database

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
trigger — this will error
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 the database
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.

List existing databases to find the correct name
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

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 versions

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

Sources
Official documentation ↗

MariaDB Server error code 1049 / ER_BAD_DB_ERROR

MariaDB CREATE DATABASE

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors