How to Fix MySQL Error 1018 (ER_CANT_READ_DIR)
You see mysql error 1018 when the database cannot read a data folder. You fix it by setting the right folder owner and read permissions. This failure uses the official symbol ER_CANT_READ_DIR and returns SQLSTATE HY000. The server reports that it cannot read the directory and gives a system number. Database teams see this issue when they list tables or drop a database. It happens because the engine relies on the host system to read folders. What causes mysql error 1018 in the database engine
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 1018 when the database cannot read a data folder. You fix it by setting the right folder owner and read permissions.
This failure uses the official symbol ER_CANT_READ_DIR and returns SQLSTATE HY000. The server reports that it cannot read the directory and gives a system number. Database teams see this issue when they list tables or drop a database. It happens because the engine relies on the host system to read folders.
What causes mysql error 1018 in the database engine
The database engine stores each schema as a folder on the disk. When you run a query to view tables, the engine scans that folder. If the host blocks this scan, the engine throws mysql error 1018 right away.
Wrong file ownership is the most common root cause in production systems. An admin might copy files into the data folder as the root user. The database service runs under a restricted system account for safety. When the database account tries to read the root files, the system blocks it.
Strict security modules on the host can also block folder reads. Tools that guard the system check every folder path before allowing a read. If you move the data folder to a new disk, those rules fail. The security tool stops the database from reading the new path.
Stray files inside a database folder also cause problems during schema drops. Someone might save a backup file or a text note inside the schema folder. When you try to drop the database, the engine only deletes known table files. The unknown files stay behind, and the folder read or delete step fails.
Disk errors or bad network mounts can trigger this error code too. If a storage volume drops offline, the host cannot read the directory tree. The system passes an input or output error back to the database engine.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
How to diagnose and fix the directory read failure safely
Start by reading the full error message in the database log. Look at the system error number at the end of the text line. That number tells you why the operating system blocked the folder read. An access denied alert points to bad user permissions or security rules. An input or output alert points to a bad disk or lost mount.
Check the folder path shown in the alert on your database host. Verify that the database service account owns the folder and all files inside. If another user owns the folder, change the owner back to the database user. Do not grant full read and write rights to every user on the host. Wide permissions put your data at risk and break basic security rules.
Keep permissions tight so only the database account can read the folder. Next, check if a host security tool blocked the read action. Review the system audit log to see if a security policy stopped the database. Update the file labels so the security tool allows the database to read there. Never turn off the host security tool just to clear the error.
How to prevent folder permission drift in production
Permission errors often happen when engineers log into database hosts by hand. Manual file edits on the server leave files with the wrong owner. You can stop this by removing direct shell logins to database hosts.
Run all backups and schema changes through standard database client tools instead. When teams use standard SQL paths, the database engine writes all files itself. The engine always uses the right system account and sets the right permissions. Keep your file system monitoring active to catch disk problems early.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
What does SQLSTATE HY000 mean with ER_CANT_READ_DIR?
SQLSTATE HY000 is a general error code for issues that lack a specific class. You must read the ER_CANT_READ_DIR symbol and system number to find the exact cause.
Why does mysql error 1018 happen when I drop a database?
The engine cannot finish reading or clearing the schema folder on the disk. This happens when non-table files sit in the folder or permissions block the user.
Can a failing hard drive cause error 1018 in MySQL?
Yes, damaged disk sectors or a dropped storage mount prevent folder reads. Check your system logs for disk hardware alerts if file permissions look right.
Related guides
In this post