Low severityschema
MySQL Error:
1008, Database Doesn't Exist
What does this error mean?
MySQL raises error 1008 (ER_DB_DROP_EXISTS) when a DROP DATABASE statement targets a database name that does not exist on the server. The server checks the data directory for a matching subdirectory and, if absent, returns ERROR 1008 (HY000): Can't drop database 'db_name'; database doesn't exist. In data pipelines this typically surfaces during environment teardown steps, CI/CD cleanup jobs, or dbt run-operation calls that drop staging schemas between runs. The symptom in orchestrators like ADF or Airflow is a failed Script or Stored Procedure activity with exit code 1 and the 1008 error in stderr. The statement is non-transactional — any objects already removed before the failure stay removed.
Common causes
- 1The database was already dropped by a previous run of the same teardown script, and the script does not use IF EXISTS.
- 2A typo in the database name — e.g., analytics_stg vs analytics_staging — causes the DROP to target a name that was never created.
- 3The MySQL connection string points to a different server or instance than intended (common when dev/staging/prod share similar hostnames).
- 4An earlier migration step that was supposed to CREATE the database failed silently, so the database never existed in the first place.
- 5dbt's run-operation or on-run-end hook issues DROP DATABASE against a schema that was already cleaned up by a parallel job or a cron-based cleanup process.
- 6Replication lag: a DROP DATABASE was executed on the primary but the script immediately re-runs on a replica where the DROP has not yet propagated.
How to fix it
- 1Step 1: Switch to the idempotent form: `DROP DATABASE IF EXISTS your_db;` — this returns a warning (Note 1008) instead of a fatal error.
- 2Step 2: Confirm which databases exist on the target server: `SHOW DATABASES;` or `SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'your_db';`
- 3Step 3: Verify you are connected to the correct host: `SELECT @@hostname, @@port;` and compare with your connection string.
- 4Step 4: Check if a previous step failed and never created the database: review the pipeline run log for earlier CREATE DATABASE failures or skipped steps.
- 5Step 5: For dbt projects, wrap teardown macros in an existence check: `{% if adapter.check_schema_exists(database, schema) %} ... {% endif %}`.
- 6Step 6: If the database name is dynamic (e.g., branch-based CI databases), log the resolved name before the DROP to catch typos: `SELECT CONCAT('Dropping: ', 'your_db') AS info; DROP DATABASE IF EXISTS your_db;`
- 7Step 7: After fixing, run `SHOW WARNINGS;` immediately after the DROP IF EXISTS to confirm the 1008 note is returned cleanly — this validates idempotency without masking other issues.
Example log output
ERROR 1008 (HY000) at line 3: Can't drop database 'analytics_staging'; database doesn't exist