Common SQL Errors

MySQL Error 21: EE_CANT_MKDIR - Can't create directory – How to Fix and Prevent

Galaxy Team
August 5, 2025

MySQL cannot create the required directory for a database, tablespace, or temporary file because the operating system returns an error.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 21 (EE_CANT_MKDIR)?

MySQL Error 21: EE_CANT_MKDIR occurs when MySQL tries to create a directory but the operating system blocks the action, usually due to missing permissions, nonexistent paths, or full disks. Grant write permissions to the MySQL OS user or free space to resolve the issue.

Error Highlights

Typical Error Message

Can't create directory '%s' (OS errno %d - %s)

Error Type

Filesystem / Permission Error

Language

MySQL

Symbol

EE_CANT_MKDIR

Error Code

21

SQL State

Explanation

Table of Contents

What does “Can't create directory” mean in MySQL?

MySQL raises EE_CANT_MKDIR when it asks the operating system to create a directory and the call fails. The message returns the directory path, OS errno, and a human-readable description so you can diagnose the underlying filesystem problem.

The error commonly surfaces during CREATE DATABASE, tablespace creation, ALTER TABLE … DISCARD/IMPORT TABLESPACE, or heavy use of disk-based temp tables.

Any action that needs a new folder inside datadir or tmpdir can trigger it.

Why is fixing EE_CANT_MKDIR important?

This error blocks database creation, import, or writes, halting application features that rely on those operations.

Leaving it unresolved risks service outages, failed deployments, and data-loss scenarios if temp files cannot be written.

What Causes This Error?

Filesystem permission issues prevent the mysqld process from writing inside datadir, tmpdir, or the target path.

A missing or mistyped directory path in my.cnf (datadir, innodb_data_home_dir, tmpdir) leads MySQL to request a non-existent location.

Disk partitions with 0 bytes free space cause the OS to refuse directory creation, returning ENOSPC.

Mandatory Access Control systems like SELinux or AppArmor block mysqld even when UNIX permissions appear correct, returning EACCES.

Operating system inode exhaustion stops new directory creation even when space is available.

How to Fix MySQL Error 21: EE_CANT_MKDIR

Verify the path in the error message exists and is spelled correctly.

If missing, create it with mkdir and correct ownership.

Grant write, read, and execute rights to the MySQL system user (e.g., mysql) on the directory and all parent folders.

Check free disk space with df -h and free inodes with df -i; expand the filesystem or clean files if necessary.

If SELinux is enforcing, run setenforce 0 temporarily or add the proper context using chcon -t mysqld_db_t /path.

With AppArmor, adjust /etc/apparmor.d/usr.sbin.mysqld to include the new directory and reload profiles.

Common Scenarios and Solutions

CREATE DATABASE db1 fails - ensure /var/lib/mysql/db1 exists, chown mysql:mysql -R /var/lib/mysql/db1, and repeat the statement.

InnoDB file-per-table import fails - run ALTER TABLESPACE … DISCARD TABLESPACE after verifying the tablespace directory path is writable.

Temp dir full during large sorts - edit my.cnf: tmpdir = /mnt/mysqltmp, mkdir /mnt/mysqltmp && chown mysql:mysql /mnt/mysqltmp.

Best Practices to Avoid This Error

Keep datadir and tmpdir on dedicated partitions with monitoring for space and inode usage.

Automate directory creation and permission checks in deployment scripts or configuration management.

Add SELinux/AppArmor rules when introducing new data paths rather than disabling security layers globally.

Use Galaxy’s pre-query validation hooks to surface filesystem errors early in development environments.

Related Errors and Solutions

OS errno 28 - No space left on device: free space or extend the volume.

OS errno 13 - Permission denied: adjust UNIX permissions or SELinux contexts.

mysqld: [ERROR] InnoDB: Unable to create the shared tablespace: similar root cause, apply the same directory and permission fixes.

.

Common Causes

Missing directory path

mysqld points to a folder that has not been created, often after editing datadir or tmpdir in my.cnf.

Insufficient UNIX permissions

The MySQL system user lacks write or execute rights on the parent directory hierarchy.

Disk or inode exhaustion

The underlying partition is full or has no remaining inodes, leading the OS to refuse mkdir.

SELinux/AppArmor policy blocks

Mandatory Access Control denies mysqld access, resulting in EACCES despite correct UNIX permissions.

Readonly or failed filesystem

If the partition has switched to read-only due to disk errors, MySQL cannot create new folders.

.

Related Errors

FAQs

Does EE_CANT_MKDIR always mean a permission problem?

No, it can also indicate disk full, inode exhaustion, or security policies blocking access.

Can I fix the error from SQL alone?

Usually not. The root cause sits at the operating system layer, so you need to adjust filesystem paths, permissions, or disk space first.

Is it safe to disable SELinux to solve the error?

Disabling SELinux removes protection. Prefer adding a policy or changing context with chcon instead of turning it off in production.

How does Galaxy help prevent EE_CANT_MKDIR?

Galaxy’s local run-history shows OS errnos immediately, and its pre-flight checks alert you to unwritable paths before executing DDL in production.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo