1007
MariaDBERRORCommonDDLHIGH confidence
Can't create database — database already exists
Production Risk
Low — error is informational; no data is affected.
What this means
ER_DB_CREATE_EXISTS (1007, SQLSTATE HY000) is raised when CREATE DATABASE is called for a database that already exists and IF NOT EXISTS was not used.
Why it happens
- 1CREATE DATABASE called without IF NOT EXISTS on an existing database
- 2Deployment script runs idempotently without the guard clause
How to reproduce
trigger — this will error
trigger — this will error
CREATE DATABASE existing_db;
expected output
ERROR 1007 (HY000): Can't create database 'existing_db'; database exists
Fix
Use CREATE DATABASE IF NOT EXISTS
WHEN Always — use the guard clause in migration scripts.
Use CREATE DATABASE IF NOT EXISTS
CREATE DATABASE IF NOT EXISTS existing_db;
Why this works
IF NOT EXISTS suppresses the error when the database already exists, making the statement idempotent.
What not to do
✕ Drop and recreate the database to work around 1007
DROP DATABASE destroys all tables and data inside it; use IF NOT EXISTS instead.
Sources
Official documentation ↗
MySQL 8.0 — 1007 ER_DB_CREATE_EXISTS
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev