MySQL raises error 1007 (ER_DB_CREATE_EXISTS) when a CREATE DATABASE statement targets a database name that is already present on the server.
MySQL Error 1007: ER_DB_CREATE_EXISTS appears when you run CREATE DATABASE for a name that already exists. Use IF NOT EXISTS, pick another name, or DROP DATABASE first to resolve the conflict.
Can't create database '%s'; database exists
Error 1007 fires when MySQL cannot execute a CREATE DATABASE because a database with the same name already exists in the data directory.
The server returns SQLSTATE HY000 and stops the statement to prevent accidental data loss. Handling the error quickly keeps automated deployments and CI pipelines running smoothly.
The error happens most often in installation scripts that assume the database is absent.
It also appears during local development when engineers recreate schemas repeatedly.
MySQL enforces unique database names, so any name collision between the CREATE statement and an existing schema triggers Error 1007.
Add IF NOT EXISTS to the CREATE DATABASE statement to make it idempotent. Alternatively, DROP the existing database if you really want a fresh schema.
In migration tools, guard the operation with conditional logic.
Docker entrypoint scripts that always run CREATE DATABASE will fail after the first launch.
Switching to CREATE DATABASE IF NOT EXISTS keeps containers idempotent.
Automated tests that recreate schemas should use DROP DATABASE IF EXISTS followed by CREATE DATABASE to ensure a clean environment.
Always version control schema creation scripts and make them re-run safe by wrapping CREATE statements with IF NOT EXISTS.
Monitor database creation logs in CI pipelines so collisions are detected before production deployment.
Error 1008 (ER_DB_DROP_EXISTS) appears when dropping a non-existent database.
Use IF EXISTS to suppress it.
Error 1049 (ER_BAD_DB_ERROR) indicates you tried to use a database that does not exist. Create the database first or correct the name.
.
The database was created earlier by a setup script, manual command, or another application instance.
Startup or migration scripts run CREATE DATABASE every time the application launches without checking for existence.
A misconfigured DB_NAME env variable points to a production database already present on the server.
On case-sensitive systems, a perceived duplicate arises when the same name is used with different letter cases.
.
IF NOT EXISTS tells MySQL to skip creation if the schema already exists, making the command safe to run multiple times.
Only drop a database when you are sure its data is no longer needed. Always back up first in production.
Yes on Unix systems that treat names as case sensitive. "Sales" and "sales" are different. On Windows, they collide.
Galaxy flags duplicate CREATE DATABASE commands and offers a quick-fix snippet with IF NOT EXISTS, helping teams write safer migration scripts.