How to fix EE_CANTCREATEFILE (1): Can't create/write to file in MySQL

MySQLINTERMEDIATEHIGHUpdated Dec 22, 2025ยท 185 views

This error occurs when MySQL cannot write temporary files to disk, usually due to insufficient permissions on the tmpdir, a full filesystem, or file descriptor limits being reached.

Quick fix

Fixes EE_CANTCREATEFILE (1): Can't create/write to file

df -h /tmp
  1. Check disk space on tmpdir filesystem
  2. Verify tmpdir permissions and ownership
  3. Configure alternative tmpdir location
  4. Check and increase file descriptor limits
mysql โ€” error
df -h /tmp
EE_CANTCREATEFILE (1): Can't create/write to file

What this error means

The EE_CANTCREATEFILE error indicates that MySQL server is unable to create or write temporary files to the configured temporary directory. MySQL uses temporary files for various operations including sorting large result sets, creating temporary tables, handling complex queries with GROUP BY or ORDER BY clauses, and managing query caches. This error typically appears with a file path showing where MySQL attempted to write (commonly /tmp/#sql_xxx_x.MYI or similar). The error may include an additional error code (errcode) that provides more specific details: errcode 13 indicates permission denied, errcode 2 means no such file or directory, and errcode 28 indicates no space left on device. The issue prevents MySQL from completing operations that require temporary file storage, causing queries to fail and potentially disrupting database functionality. This can affect both routine queries and administrative operations like ALTER TABLE statements.

Typical symptoms

  • Queries involving sorting or grouping fail with "Can't create/write to file" message
  • Error messages reference files in /tmp directory with patterns like #sql_xxx_x.MYI
  • Complex SELECT queries or ALTER TABLE statements fail unexpectedly
  • MySQL error log shows repeated file creation failures
  • Application receives HY000 error code from database connections

Common causes

  1. MySQL user lacks write permissions on the tmpdir directory (commonly /tmp)
  2. Temporary directory filesystem is completely full with no available disk space
  3. Temporary directory path does not exist or is incorrectly configured
  4. File descriptor limit is reached, preventing MySQL from opening new files
  5. AppArmor or SELinux security policies block MySQL access to tmpdir
  6. Antivirus software temporarily locking MySQL temporary files
  7. Incorrect ownership or missing sticky bit on /tmp directory

How to fix "EE_CANTCREATEFILE (1): Can't create/write to file"

1Check disk space on tmpdir filesystem

First, verify that the filesystem containing MySQL's temporary directory has available space.

Check disk usage:

bash
df -h /tmp

If the filesystem is full (100% usage), free up space by removing unnecessary files or expanding the filesystem. You can identify large files with:

bash
du -sh /tmp/* | sort -hr | head -20

For immediate relief on a full disk, clean up old temporary files (be cautious with this command):

bash
# Remove files older than 7 days from /tmp
find /tmp -type f -mtime +7 -delete
2Verify tmpdir permissions and ownership

Check that the temporary directory has correct permissions for MySQL to write files.

Check current permissions:

bash
ls -ld /tmp

The output should show: drwxrwxrwt (permissions 1777 with sticky bit set)

If permissions are incorrect, fix them as root:

bash
sudo chown root:root /tmp
sudo chmod 1777 /tmp

The sticky bit (1 in 1777) ensures users can only delete their own files, which is essential for /tmp security.

3Configure alternative tmpdir location

If /tmp is problematic, configure MySQL to use a different temporary directory.

Create a dedicated directory for MySQL temporary files:

bash
sudo mkdir -p /var/lib/mysql-tmp
sudo chown mysql:mysql /var/lib/mysql-tmp
sudo chmod 1777 /var/lib/mysql-tmp

Edit MySQL configuration file (/etc/my.cnf or /etc/mysql/my.cnf):

ini
[mysqld]
tmpdir = /var/lib/mysql-tmp

Restart MySQL to apply changes:

bash
sudo systemctl restart mysql
# or
sudo service mysql restart

Verify the new tmpdir is in use:

sql
SHOW VARIABLES LIKE 'tmpdir';
4Check and increase file descriptor limits

Verify that MySQL hasn't reached its file descriptor limit.

Check current limits while MySQL is running:

sql
SHOW VARIABLES LIKE 'open_files_limit';

Check system limit for MySQL process:

bash
cat /proc/$(pgrep -f mysqld)/limits | grep 'open files'

If the limit is too low (default is often 1024), increase it in MySQL configuration:

ini
[mysqld]
open_files_limit = 65535

Also update systemd service limits (for systemd-managed MySQL):

bash
sudo mkdir -p /etc/systemd/system/mysql.service.d/
sudo nano /etc/systemd/system/mysql.service.d/limits.conf

Add:

ini
[Service]
LimitNOFILE=65535

Reload systemd and restart MySQL:

bash
sudo systemctl daemon-reload
sudo systemctl restart mysql
5Address AppArmor or SELinux restrictions

Security modules may prevent MySQL from accessing temporary directories.

For AppArmor (Ubuntu/Debian), check if it's blocking MySQL:

bash
sudo aa-status | grep mysql
sudo dmesg | grep -i apparmor | grep mysql

If AppArmor is blocking access, edit the MySQL profile:

bash
sudo nano /etc/apparmor.d/local/usr.sbin.mysqld

Add your tmpdir path:

bash
/var/lib/mysql-tmp/** rw,

Reload AppArmor:

bash
sudo systemctl reload apparmor

For SELinux (RHEL/CentOS), check context:

bash
ls -Z /tmp

Set correct context for custom tmpdir:

bash
sudo semanage fcontext -a -t mysqld_tmp_t "/var/lib/mysql-tmp(/.*)?"
sudo restorecon -Rv /var/lib/mysql-tmp

Advanced notes

Monitoring Temporary File Usage: You can monitor MySQL's temporary file creation with performance schema tables. Enable file instrumentation and query the file_summary_by_instance table to identify queries creating excessive temporary files.

Temporary Table Configuration: The tmp_table_size and max_heap_table_size variables control when in-memory temporary tables spill to disk. Increasing these values (with caution regarding available RAM) can reduce the need for on-disk temporary files. However, this is a workaround rather than a fix for permission or space issues.

Read-Only Filesystems: In container environments or systems with read-only root filesystems, ensure tmpdir points to a writable volume. Docker containers should mount a volume for MySQL's tmpdir, and Kubernetes deployments should use emptyDir volumes or persistent volume claims.

Multiple tmpdir Paths: MySQL supports specifying multiple tmpdir locations separated by colons (Linux/Unix) or semicolons (Windows). MySQL will use these in round-robin fashion: tmpdir=/tmp:/var/tmp. This can provide redundancy if one filesystem fills up.

Errcode Reference: Common errcodes include: 13 (EACCES - permission denied), 2 (ENOENT - no such file/directory), 28 (ENOSPC - no space left), 30 (EROFS - read-only filesystem), 24 (EMFILE - too many open files). These map to standard POSIX error codes and can help diagnose the specific cause.

Frequently asked questions

What does "EE_CANTCREATEFILE (1): Can't create/write to file" mean?
The EE_CANTCREATEFILE error indicates that MySQL server is unable to create or write temporary files to the configured temporary directory. MySQL uses temporary files for various operations including sorting large result sets, creating temporary tables, handling complex queries with GROUP BY or ORDER BY clauses, and managing query caches. MYI or similar).
How do I fix "EE_CANTCREATEFILE (1): Can't create/write to file"?
This error occurs when MySQL cannot write temporary files to disk, usually due to insufficient permissions on the tmpdir, a full filesystem, or file descriptor limits being reached.
What causes "EE_CANTCREATEFILE (1): Can't create/write to file"?
MySQL user lacks write permissions on the tmpdir directory (commonly /tmp) Temporary directory filesystem is completely full with no available disk space Temporary directory path does not exist or is incorrectly configured
Is the "EE_CANTCREATEFILE (1): Can't create/write to file" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading