MySQL throws Error 1049 (ER_BAD_DB_ERROR) when a requested database name does not exist or is inaccessible.
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.
Unknown database '%s'
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.
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.
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.
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.
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.
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.
.
No. A spelling mistake or lack of privileges can produce the same error even when the database still exists.
Yes. On case-sensitive file systems, MySQL treats mydb and MyDB as different schemas, so case mismatches trigger 1049.
Yes. Create the database or adjust privileges on a running server; no restart is required.
Galaxy’s schema browser auto-completes valid database names and flags typos before the query runs, reducing Error 1049 incidence.