MySQL cannot create the required directory for a database, tablespace, or temporary file because the operating system returns an error.
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.
Can't create directory '%s' (OS errno %d - %s)
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.
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.
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.
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.
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.
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.
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.
.
mysqld points to a folder that has not been created, often after editing datadir or tmpdir in my.cnf.
The MySQL system user lacks write or execute rights on the parent directory hierarchy.
The underlying partition is full or has no remaining inodes, leading the OS to refuse mkdir.
Mandatory Access Control denies mysqld access, resulting in EACCES despite correct UNIX permissions.
If the partition has switched to read-only due to disk errors, MySQL cannot create new folders.
.
No, it can also indicate disk full, inode exhaustion, or security policies blocking access.
Usually not. The root cause sits at the operating system layer, so you need to adjust filesystem paths, permissions, or disk space first.
Disabling SELinux removes protection. Prefer adding a policy or changing context with chcon instead of turning it off in production.
Galaxy’s local run-history shows OS errnos immediately, and its pre-flight checks alert you to unwritable paths before executing DDL in production.