Common SQL Errors

MySQL Error 1049: ER_BAD_DB_ERROR - Unknown Database '%s' Explained and Fixed

Galaxy Team
August 5, 2025

MySQL throws Error 1049 (ER_BAD_DB_ERROR) when a requested database name does not exist or is inaccessible.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1049 (ER_BAD_DB_ERROR)?

MySQL Error 1049: ER_BAD_DB_ERROR means the server cannot locate the database specified in your connection or query. Verify the schema name, create the database if missing, or adjust user privileges. Creating the database or correcting the DSN resolves the issue quickly.

Error Highlights

Typical Error Message

Unknown database '%s'

Error Type

Connection Error

Language

MySQL

Symbol

ER_BAD_DB_ERROR

Error Code

1049

SQL State

Explanation

Table of Contents

What is MySQL Error 1049 (ER_BAD_DB_ERROR)?

Error 1049 appears when MySQL cannot find the database referenced in a connection string, USE statement, or SQL query. The server responds with the message Unknown database '%s', where %s is the missing schema name.

The error blocks the session from running any further SQL because the connection has no current schema.

Understanding why the database is missing or inaccessible is critical for fast recovery.

What Causes This Error?

A typo in the database name is the most frequent trigger. Even a single misplaced character forces MySQL to treat the target as non-existent.

The database may have been dropped accidentally during development, by a failed migration, or after a restore that excluded certain schemas.

Insufficient privileges can also surface the error.

If the user lacks the SHOW DATABASES or USE privilege, MySQL responds as if the schema does not exist.

How to Fix MySQL Error 1049

First, double-check the database name in your DSN, CLI command, or USE statement.

Correct spelling and case sensitivity usually clear the problem.

If the schema truly is missing, recreate it with CREATE DATABASE and re-run migrations or imports to restore tables and data.

When privileges are the culprit, grant the necessary rights using GRANT ALL PRIVILEGES ON db_name.* TO 'user'@'host'; followed by FLUSH PRIVILEGES.

Common Scenarios and Solutions

Local dev environments often break after a git pull if new databases have not been created.

Running the project’s bootstrap script or docker-compose process recreates the schema.

CI pipelines may reference a test database that was never created on the runner. Add a CREATE DATABASE step before executing integration tests.

In production, a failover to a replica missing the schema triggers 1049.

Ensure replication includes all schemas or use pt-clone to copy them.

Best Practices to Avoid This Error

Automate schema creation in deployment scripts so that every environment starts with the required databases.

Use IF NOT EXISTS in CREATE DATABASE to make scripts idempotent. Version control migrations with tools like Flyway or Liquibase.

Monitor MySQL error logs and set up alerts for Error 1049.

Early detection prevents prolonged downtime.

Related Errors and Solutions

Error 1044 (ER_DBACCESS_DENIED_ERROR) signals privilege issues rather than absence. Grant proper rights to fix.

Error 1146 (ER_NO_SUCH_TABLE) appears when the database exists but a table does not. Recreate or rename the table appropriately.

Error 2002 (HY000) indicates a socket or TCP connection failure, not a missing database. Check host and port configuration.

.

Common Causes

Related Errors

FAQs

Does Error 1049 always mean the database was dropped?

No. A spelling mistake or lack of privileges can produce the same error even when the database still exists.

Is Error 1049 case sensitive on Linux?

Yes. On case-sensitive file systems, MySQL treats mydb and MyDB as different schemas, so case mismatches trigger 1049.

Can I fix Error 1049 without restarting MySQL?

Yes. Create the database or adjust privileges on a running server; no restart is required.

How does Galaxy help prevent this error?

Galaxy’s schema browser auto-completes valid database names and flags typos before the query runs, reducing Error 1049 incidence.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo