How to Fix MySQL Error 3678 (ER_SCHEMA_DIR_EXISTS)
You see mysql error 3678 when the database finds an existing folder for a new schema. You fix it by moving the leftover folder out of the data path on disk. The server reports the ER_SCHEMA_DIR_EXISTS symbol and SQLSTATE HY000 when this state occurs. It happens when the internal data dictionary and the host file system fall out of sync. The database thinks the schema does not exist, yet the host operating system still holds the directory.MySQL stops the request to protect any files that still s
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You see mysql error 3678 when the database finds an existing folder for a new schema. You fix it by moving the leftover folder out of the data path on disk.
The server reports the ER_SCHEMA_DIR_EXISTS symbol and SQLSTATE HY000 when this state occurs. It happens when the internal data dictionary and the host file system fall out of sync. The database thinks the schema does not exist, yet the host operating system still holds the directory.MySQL stops the request to protect any files that still sit inside that folder.
What causes mysql error 3678 in the database engine
MySQL maps each schema to a dedicated directory inside the main data folder on disk. When you create a schema, the engine checks its internal catalog first. Next, it asks the operating system to make a new directory with that schema name. If a folder with that exact name is already on the disk, the engine stops.
Several operational events leave behind an orphan directory on the storage volume. A past schema drop might have failed halfway due to a sudden power loss or crash. Sometimes an engineer places a backup file or a text log inside the schema directory. When someone drops the schema later, MySQL deletes its own table files. Still, the operating system refuses to remove the folder because unknown files remain inside it.
Manual file copies also trigger this problem during server migrations. An admin might copy folders straight into the data directory without registering them in the catalog. When an automated script runs later to create that schema, it hits the existing folder. Replication replicas can also halt if a primary node sends a creation event to a dirty replica disk.
How to diagnose and fix the failure in production
Read the full error message to find the exact directory name causing the block. Do not give developers root access to the database host to delete folders on their own. Instead, have a system admin inspect the storage path on the server. Check what files sit inside the conflicting directory before you change anything.
If the folder holds only stray text files or old crash logs, move the folder out. Move it to a safe backup directory on the same disk volume first. Do not delete the folder right away in case someone needs those files later. Make sure the operating system user that runs the database owns the parent data directory.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Sometimes the folder holds valid table files from an old database. In that case, do not delete them. Work with your storage team to restore those files on a separate test instance first. Once the conflicting directory is out of the main data path, run the schema creation task again. The database will build a fresh folder and update its internal catalog without errors.
How to prevent leftover schema folders
Keep human users out of the raw database storage directories on your production hosts. Store backups, scripts, and diagnostic logs on a separate disk volume away from live data files. When no extra files sit inside schema folders, the database can drop directories cleanly every time.
Set up your deployment pipelines to check if a schema exists before trying to create it. Limit who can run schema drop and create commands on production instances. Use strict role rules so only approved migration tools alter your database structure. Clean audit logs also help you see who ran schema changes right before an error occurred.
Inspect every MySQL query and response in flight
Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.
First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.
Frequently asked questions
What does ER_SCHEMA_DIR_EXISTS mean in MySQL?
This symbol means the database tried to create a schema, but the disk folder already exists. The engine blocks the action under SQLSTATE HY000 so it does not overwrite existing files.
Can I fix mysql error 3678 without host disk permissions?
No, you cannot remove an orphan operating system folder using standard database queries alone. You must move the folder on the disk or pick a different name for your new schema.
Why did an old schema folder stay on the disk after a drop?
A schema drop leaves the folder behind if non-database files sit inside that directory. A sudden server crash during a drop operation can also leave an empty folder on disk.
Related guides
In this post