How to fix ERROR 1010: Error dropping database (can't rmdir) in MySQL
ERROR 1010 occurs when MySQL cannot remove a database directory due to extra files or permission issues. The directory contains files that MySQL doesn't recognize or can't delete, preventing the DROP DATABASE command from completing successfully.
Quick fix
Fixes ERROR 1010: Error dropping database (can't rmdir)
SHOW VARIABLES WHERE Variable_name LIKE 'datadir%';- Check the MySQL data directory location
- Stop the MySQL server
- List files in the database directory
- Remove extra files manually
SHOW VARIABLES WHERE Variable_name LIKE 'datadir%';ERROR 1010: Error dropping database (can't rmdir)
What this error means
MySQL ERROR 1010 (HY000) is a file system error that occurs during the DROP DATABASE operation. When you drop a database, MySQL removes the associated table files (.ibd, .frm, etc.) and then attempts to delete the database directory itself. If the directory is not empty or contains files that MySQL doesn't recognize—such as backups, temporary files, or binary log files—the directory removal fails. The error is accompanied by an errno value that provides more context: - errno 17: "File exists" - the directory contains unrecognized MySQL files - errno 39: "Directory not empty" - hidden or extra files remain - errno 41: Similar directory removal issue This is typically a file system permission or cleanup issue rather than a MySQL functionality problem.
Typical symptoms
- DROP DATABASE command fails with "Error dropping database (can't rmdir)"
- Error includes an errno value (17, 39, or 41)
- Database records in MySQL are gone but directory removal fails
- Database can be recreated with the same name only after manual directory removal
Common causes
- Extra files in the database directory not created by MySQL (backups, temporary files, hidden files)
- Binary log files stored in a subdirectory of the MySQL data directory
- Insufficient file system permissions for the MySQL system user to delete the directory
- Files locked by other processes or applications preventing removal
- Hidden system files (.DS_Store on macOS, thumbs.db on Windows) in the database directory
How to fix "ERROR 1010: Error dropping database (can't rmdir)"
First, find where MySQL stores database files:
SHOW VARIABLES WHERE Variable_name LIKE 'datadir%';This typically returns /var/lib/mysql/ on Linux, /usr/local/mysql/data/ on macOS, or C:\ProgramData\MySQL\MySQL Server 8.0\Data\ on Windows.
Before manually removing files, stop MySQL to prevent any locking issues:
Linux (systemd):
sudo systemctl stop mysqlLinux (service):
sudo service mysql stopmacOS:
sudo /usr/local/mysql/support-files/mysql.server stopWindows (Command Prompt as Administrator):
NET STOP MySQL80Navigate to the data directory and list all files (including hidden ones) in the problematic database folder:
Linux/macOS:
ls -la /var/lib/mysql/database_name/Windows (PowerShell):
Get-ChildItem -Path "C:\ProgramData\MySQL\MySQL Server 8.0\Data\database_name" -ForceLook for files that don't belong, such as:
- .DS_Store or Thumbs.db (system files)
- .backup or .bak files
- .sql or .dump files
- Any hidden files (prefix with dot)
Delete the unrecognized files from the directory:
Linux/macOS:
cd /var/lib/mysql/database_name/
rm -f extra_file.txt
rm -f .DS_StoreWindows (PowerShell as Administrator):
cd "C:\ProgramData\MySQL\MySQL Server 8.0\Data\database_name"
Remove-Item -Path "extra_file.txt" -Force
Remove-Item -Path ".DS_Store" -ForceIf the directory is now completely empty, you can optionally remove it:
Linux/macOS:
cd /var/lib/mysql/
rmdir database_nameStart MySQL again:
Linux (systemd):
sudo systemctl start mysqlLinux (service):
sudo service mysql startmacOS:
sudo /usr/local/mysql/support-files/mysql.server startWindows (Command Prompt as Administrator):
NET START MySQL80Now attempt to drop the database again:
DROP DATABASE database_name;The command should succeed now that the directory contains only MySQL-managed files.
Advanced notes
Binary Logs in Data Directory: If you see mysql-bin/ or similar binary log directories inside your data directory, update your MySQL configuration file (my.cnf or my.ini) to store binary logs elsewhere:
[mysqld]
log_bin = /var/log/mysql/mysql-binThen restart MySQL and retry the DROP DATABASE command.
Permission Issues: If you see "Permission denied" errors, ensure the MySQL system user owns the data directory:
sudo chown -R mysql:mysql /var/lib/mysql/
sudo chmod 750 /var/lib/mysql/SELinux/AppArmor: On systems with mandatory access controls, check that MySQL has permission to access and delete files in the data directory. You may need to consult your system's security policies.
Backups Before Deletion: Always verify you have backups of any data before manually deleting files. If the database needs to be recovered, ensure you have dumps or backups in another location.
Frequently asked questions
- What does "ERROR 1010: Error dropping database (can't rmdir)" mean?
- MySQL ERROR 1010 (HY000) is a file system error that occurs during the DROP DATABASE operation. ) and then attempts to delete the database directory itself. If the directory is not empty or contains files that MySQL doesn't recognize—such as backups, temporary files, or binary log files—the directory removal fails.
- How do I fix "ERROR 1010: Error dropping database (can't rmdir)"?
- ERROR 1010 occurs when MySQL cannot remove a database directory due to extra files or permission issues. The directory contains files that MySQL doesn't recognize or can't delete, preventing the DROP DATABASE command from completing successfully.
- What causes "ERROR 1010: Error dropping database (can't rmdir)"?
- Extra files in the database directory not created by MySQL (backups, temporary files, hidden files) Binary log files stored in a subdirectory of the MySQL data directory Insufficient file system permissions for the MySQL system user to delete the directory
- Is the "ERROR 1010: Error dropping database (can't rmdir)" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚MySQL Official Documentation
- 📖MySQL Error Reference(Official Docs)
- 📝
- 💬AWS re:Post - Drop Database Discussion(Stack Overflow)