Error
Error Code:
1007
MariaDB Error 1007: Database Already Exists
Description
This error signifies that you attempted to create a database using a name that already exists on the MariaDB server. It typically occurs when a `CREATE DATABASE` statement is executed without first verifying the database's existence, leading to a naming conflict.
Error Message
Can't create database '%s'; database exists
Known Causes
3 known causesManual Duplicate Database Creation
A user manually executed a `CREATE DATABASE` command with a name that is already present on the server.
Script Rerun Without Checks
An installation script, migration tool, or application re-attempted to create a database that was already set up in a previous run.
Typographical Error or Misconfiguration
The database name specified in a script or command might be incorrect, inadvertently matching an existing database.
Solutions
4 solutions available1. Use IF NOT EXISTS Clause easy
Prevent error by checking existence first
1
Use CREATE DATABASE with IF NOT EXISTS
CREATE DATABASE IF NOT EXISTS my_database;
2
This is the recommended approach for scripts
-- Safe for repeated execution
CREATE DATABASE IF NOT EXISTS app_production
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
2. Check Existing Databases First easy
List databases before creating
1
List all existing databases
SHOW DATABASES;
2
Check if specific database exists
SHOW DATABASES LIKE 'my_database';
3
In a script, check programmatically
SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME = 'my_database';
3. Drop and Recreate Database medium
Remove existing database to create fresh one
1
Drop the existing database (WARNING: destroys all data)
DROP DATABASE my_database;
2
Create the database fresh
CREATE DATABASE my_database
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
3
For scripts, use DROP IF EXISTS first
DROP DATABASE IF EXISTS my_database;
CREATE DATABASE my_database;
4. Use Different Database Name easy
Choose a unique name for your new database
1
List existing databases to find available name
SHOW DATABASES;
2
Create with a unique name
-- Add version or date suffix
CREATE DATABASE my_database_v2;
CREATE DATABASE my_database_2026;