MySQL Unknown Database Error: Case-Sensitivity Traps, Pre-Migration DDL Gaps & Flyway/Liquibase Best Practices
Addressing 1049 errors caused by casing mismatch, missing pre-migration databases, and dump restore context errors with idempotent scripts.
Operational Verification & Reliability Metadata
The error string is a symptom, not the root cause. Do not restart the server blindly. Run the diagnostic queries below to pinpoint the actual failure mode.
▸Symptom
Applications fail during bootstrap or during dump restore operations with:
ERROR 1049 (42000): Unknown database 'prod_v2'▸What You See in Production
CI/CD deployment pipelines break immediately on migration steps, or application containers fail readiness checks.
▸Root Cause Matrix
| Probability | Root Cause | Description |
|---|---|---|
| %60 | Missing Pre-Migration Database | Migration engines expect pre-existing target databases before executing DDL. |
| %25 | Case Sensitivity Traps | Linux environments distinguish casing under lower_case_table_names=0. |
| %15 | Hardcoded `USE` Clauses in Dumps | Ingested dumps force context switching to non-existent schemas. |
▸EMERGENCY RUNBOOK (0-5 min)
-- 1. Inspect existing schemas
SHOW DATABASES;
-- 2. Create missing target database with proper charset
CREATE DATABASE IF NOT EXISTS prod_v2
CHARACTER SET utf8mb4
COLLATE utf8mb4_0900_ai_ci;
-- 3. Grant application user permissions
GRANT ALL PRIVILEGES ON prod_v2.* TO 'app_user'@'%';
FLUSH PRIVILEGES;▸PERMANENT BLUEPRINT
- 1Standardized Encodings: Enforce
utf8mb4andutf8mb4_0900_ai_ciuniformly. - 2Idempotent CI/CD Ingestion: Enforce automated pre-flight creation hooks in migration runners.
▸Verification
SELECT schema_name, default_character_set_name FROM information_schema.schemata WHERE schema_name = 'prod_v2';Other Database Error Triage Playbooks
Other battle-tested diagnostic guides for high-severity database errors.
MySQL ERROR 1045 Access denied: root Password Reset Guide
Four causes of MySQL 1045, meaning of using password: YES/NO, and safe credential recovery via --init-file.
MySQL Deadlock ERROR 1213: Graph Analysis and Permanent Prevention
Root causes of MySQL 1213 deadlock, parsing LATEST DETECTED DEADLOCK output, gap lock concurrency issues, and resilient application retry design.
MySQL Lock wait timeout exceeded: Finding Blocking Sessions
Finding the blocking transaction using performance_schema, safe KILL decision matrices, and permanent locking reduction.