Error Dropping Database Can't rmdir '.test', errno 17
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Error dropping database: Can't rmdir '.test', errno 17 means MySQL could not remove the schema directory from the filesystem after drop processing started. This is usually a storage or process state issue, not a SQL syntax problem. Safe recovery requires checking active connections, directory contents, permissions, and service logs before manual deletion.
What the Error Usually Implies
Errno seventeen in this context typically indicates directory removal conflict. Common causes:
- schema directory is not empty
- another process holds file handles
- unexpected files were created in the schema folder
- filesystem permissions or mount behavior prevent removal
Treat it as a data-directory hygiene issue first.
Step 1: Locate Datadir and Inspect Schema Folder
Start by confirming the exact MySQL datadir location.
Then inspect the schema directory on disk.
If you find unknown files, identify origin before deleting. Backup tooling, plugins, or manual scripts can leave artifacts that block directory removal.
Step 2: Check Active Sessions and Background Jobs
Open sessions can keep resources busy during drop operations.
Terminate stale sessions carefully if needed.
Also check for backup agents, antivirus scanners, or indexers touching datadir paths.
Step 3: Retry SQL-Level Cleanup
Before touching files manually, retry cleanup through SQL:
Dropping remaining objects can reveal exactly which file type causes failure.
Step 4: Controlled Manual Recovery
If SQL retries fail and backups are confirmed, move the directory while MySQL is stopped.
Moving instead of deleting preserves recovery options if you discover unexpected contents later.
Step 5: Verify Ownership, Permissions, and Disk Health
Permission drift can make drop operations fail repeatedly.
Review MySQL error logs for root cause details.
If failures continue, inspect kernel messages for filesystem issues.
Do not keep retrying destructive operations without log evidence.
Post-Fix Validation Checklist
After remediation, run a quick health check:
Then confirm corresponding directory appears and disappears correctly. This validates that drop behavior is restored.
Prevention Practices
To reduce recurrence:
- avoid manual edits inside live datadir
- use clean service shutdown for maintenance
- monitor DDL failures centrally
- keep tested restore procedures
- quarantine suspicious schema directories before deletion
Operational discipline prevents most repeat incidents.
Automation Guardrails
If you automate schema cleanup in CI or maintenance jobs, include guardrails:
- verify target schema name against allowlist
- confirm recent backup snapshot exists
- block destructive operations during active backup windows
- require explicit dry-run mode output
These checks prevent accidental production impact while troubleshooting.
Backup and Restore Readiness
Any manual datadir intervention should be paired with tested restore procedures. Teams often take backups but do not validate restore speed or completeness. Running regular restore drills ensures that emergency cleanup decisions remain reversible under time pressure.
Common Pitfalls
A common pitfall is deleting files while MySQL is still running. This can create metadata inconsistency and harder recovery.
Another issue is assuming every drop failure is SQL-level and skipping filesystem inspection.
Teams also perform permanent delete immediately instead of quarantine move, removing forensic context and rollback options.
Summary
- Errno seventeen on drop usually means directory removal conflict in datadir.
- Diagnose with session checks, folder inspection, and server logs first.
- Prefer SQL cleanup before manual filesystem intervention.
- Use stop, move, restart workflow for safer manual recovery.
- Validate drop behavior after fix and add operational guardrails to prevent recurrence.
Related reading
- Error found in Chart.yaml, but missing in charts/ directory mysql
- Error in MySQL when setting default value for DATE or DATETIME
- Error in Oracle Coherence - no storage-enabled nodes exist for service partitionedcache while using Cohql in production
- Error in TiDB `java.sql.BatchUpdateExecptionstatement count 5001 exceeds the transaction limitation`
- ERROR Error when sending message to topic
- Error executing Hello World for AWS Lambda in Java
- Error installing mysql2 Failed to build gem native extension
- Error related to only_full_group_by when executing a query in MySql

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.