Error
Error Code: 1008

MariaDB Error 1008: Database Does Not Exist

📦 MariaDB
📋

Description

MariaDB Error 1008 indicates that you are attempting to drop a database that the server cannot find. This error occurs when the specified database name does not correspond to any existing database on the connected MariaDB instance, preventing the DROP DATABASE operation from completing successfully.
💬

Error Message

Can't drop database '%s'; database doesn't exist
🔍

Known Causes

3 known causes
⚠️
Incorrect Database Name
The database name provided in the DROP DATABASE statement contains a typo, a misspelling, or incorrect casing, causing MariaDB to fail to locate it.
⚠️
Database Already Dropped
The database you are trying to drop has already been removed by a previous operation or another user, and thus no longer exists.
⚠️
Wrong Server Context
You are connected to a different MariaDB server or instance where the intended database does not exist, even if it might exist on another server.
🛠️

Solutions

4 solutions available

1. Use IF EXISTS Clause easy

Prevent error by checking existence before dropping

1
Use DROP DATABASE with IF EXISTS
DROP DATABASE IF EXISTS my_database;
2
This is safe for scripts that may run multiple times
-- Won't error if database doesn't exist
DROP DATABASE IF EXISTS old_database;
DROP DATABASE IF EXISTS temp_database;

2. Verify Database Name easy

Check spelling and list available databases

1
List all databases to find correct name
SHOW DATABASES;
2
Search for databases with similar names
SHOW DATABASES LIKE '%mydb%';
3
Check exact case (important on Linux)
-- Linux is case-sensitive
SHOW DATABASES LIKE 'MyDatabase';  -- different from 'mydatabase'

3. Verify Server Connection easy

Ensure you're connected to the correct server

1
Check which server you're connected to
SELECT @@hostname, @@port;
2
Show connection information
STATUS;
3
Connect to the correct server explicitly
mysql -h correct_server_hostname -P 3306 -u username -p

4. Check for Orphaned Database Directory advanced

Handle cases where DB files exist but DB is not registered

1
Check if database directory exists on disk
sudo ls -la /var/lib/mysql/ | grep -i database_name
2
If directory exists but SHOW DATABASES doesn't list it, restart MariaDB
sudo systemctl restart mariadb
3
If still not visible, manually remove orphaned directory (careful!)
sudo systemctl stop mariadb
sudo rm -rf /var/lib/mysql/orphaned_database_name
sudo systemctl start mariadb
🔗

Related Errors

5 related errors