Error
Error Code: 1009

MariaDB Error 1009: Cannot Delete Database Files

📦 MariaDB
📋

Description

This error indicates that MariaDB failed to delete the files or directories associated with a database during a `DROP DATABASE` operation. It typically occurs when the database server lacks the necessary file system permissions or the files are locked by another process.
💬

Error Message

Error dropping database (can't delete '%s', errno: %d)
🔍

Known Causes

4 known causes
⚠️
Insufficient File System Permissions
The operating system user running the MariaDB server lacks the necessary write or delete permissions for the database's data directory or specific files within it.
⚠️
Database Files Locked
One or more files belonging to the database are currently in use or locked by an external process, such as an antivirus scan, backup utility, or another application.
⚠️
Read-Only File System
The disk partition or volume where the database files are located is mounted in read-only mode, preventing MariaDB from performing any delete operations.
⚠️
Corrupted Storage
The underlying file system or storage volume where the database resides has corruption, making files undeletable by the operating system.
🛠️

Solutions

4 solutions available

1. Fix File Permissions medium

Grant MariaDB delete permissions on data directory

1
Check ownership of the database directory
sudo ls -la /var/lib/mysql/database_name/
2
Fix ownership to mysql user
sudo chown -R mysql:mysql /var/lib/mysql/database_name/
sudo chmod -R 750 /var/lib/mysql/database_name/
3
Fix parent directory permissions if needed
sudo chown mysql:mysql /var/lib/mysql/
sudo chmod 750 /var/lib/mysql/
4
Retry the DROP DATABASE command
DROP DATABASE database_name;

2. Release Locked Files medium

Find and stop processes locking database files

1
Find processes using database files (Linux)
sudo lsof +D /var/lib/mysql/database_name/
2
Check for backup processes
ps aux | grep -E 'backup|mysqldump|mariabackup'
3
Stop any interfering processes
# Example: stop a backup process
sudo kill -15 <PID>
4
Disable antivirus scanning on MySQL directory temporarily
# Add /var/lib/mysql to antivirus exclusions
# Then retry DROP DATABASE

3. Manually Remove Database Files advanced

Delete database directory manually when DROP fails

1
Stop MariaDB server first
sudo systemctl stop mariadb
2
Verify the database directory location
ls -la /var/lib/mysql/database_name/
3
Remove the database directory
sudo rm -rf /var/lib/mysql/database_name/
4
Start MariaDB server
sudo systemctl start mariadb
5
Verify database is gone
SHOW DATABASES;

4. Check Filesystem Health medium

Verify filesystem isn't read-only or corrupted

1
Check if filesystem is read-only
mount | grep /var/lib/mysql
2
Remount as read-write if needed
sudo mount -o remount,rw /var/lib/mysql
3
Check filesystem for errors
sudo dmesg | grep -i error
sudo fsck -n /dev/sdX
🔗

Related Errors

5 related errors