High severityschema
MySQL Error:
1049
What does this error mean?
MySQL throws error 1049 when the database name in a connection string, USE statement, or DSN does not exist on the target MySQL server. The server resolves the database name before any query executes, so the connection is rejected immediately — no partial reads occur. In a data pipeline this surfaces as a failed linked service test in Azure Data Factory, a dbt profile that cannot compile, or a Power BI DirectQuery dataset that errors on refresh. The engineer sees a red pipeline run with exit code 1049 and the message 'Unknown database \'your_db_name\''. Common triggers include a dropped database, a renamed database where connection strings were not updated, or a deploy pointing at the wrong environment.
Common causes
- 1The database was dropped and never recreated. A DBA or migration script issued DROP DATABASE and downstream services were not updated. Every subsequent connection attempt fails until the database is restored or the connection string is changed.
- 2A typo in the database name in the connection string or dbt profile. MySQL on Linux performs a case-sensitive match because database names map to filesystem directories under the datadir. 'Analytics' and 'analytics' are two different databases.
- 3Connecting to the wrong MySQL host. The pipeline is pointed at a staging or dev instance where the database does not exist, while the intended target is the production server. This is especially common after copying a connection string from one environment and forgetting to change the host.
- 4A database rename was performed by dumping and recreating under a new name, but at least one connection string — in an ADF linked service, a dbt profiles.yml, or a Power BI gateway configuration — still references the old name.
- 5The database exists but on a different MySQL instance or port. A multi-tenant setup may run several MySQL processes; the pipeline connects to port 3306 while the target database lives on 3307.
- 6A migration or CI/CD job that creates the database failed silently before the pipeline ran. The pipeline assumes the database was provisioned but the CREATE DATABASE statement never executed successfully.
- 7The MySQL user account used by the pipeline has been granted access to a differently-named database (e.g. 'app_prod') but the connection string specifies 'appdb_prod'. The 1049 error fires before MySQL even evaluates user permissions.
How to fix it
- 1Step 1: From a MySQL client with admin access, list all databases on the target server to confirm whether the database exists at all: `SHOW DATABASES;`
- 2Step 2: If the database is missing and should exist, create it with the correct character set: `CREATE DATABASE your_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;`
- 3Step 3: If the database exists but under a different name (e.g. a rename happened), compare the exact string in SHOW DATABASES output against your connection string. On Linux MySQL, fix the casing in the connection string — do not rename the database to match a typo.
- 4Step 4: In Azure Data Factory, open the linked service, update the Database Name field, and click Test Connection before saving. ADF caches the linked service configuration; a successful test confirms the new name is correct.
- 5Step 5: In a dbt project, open profiles.yml, correct the schema or database field for the target environment, then run `dbt debug` to verify the profile connects: `dbt debug --target prod`
- 6Step 6: For Power BI, open the Power BI Service → Settings → Datasets → select the dataset → Data source credentials → edit the connection string to match the correct database name, then trigger a manual refresh to confirm.
- 7Step 7: After fixing the connection string, verify that the MySQL user has CONNECT privileges on the newly specified database: `SHOW GRANTS FOR 'pipeline_user'@'%';` — grant access if the database was freshly created: `GRANT SELECT, INSERT, UPDATE ON your_db.* TO 'pipeline_user'@'%'; FLUSH PRIVILEGES;`
Example log output
ERROR 1049 (42000): Unknown database 'analytics_prod'
[ADF] Activity failed: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'analytics_prod' (error code: 1049)
[dbt] Database Error: (1049, "Unknown database 'analytics_prod'")