MySQL error 1004 (ER_CANT_CREATE_FILE) means the server failed to create or copy a file needed for an operation because of permissions, path, or disk issues.
MySQL Error 1004: ER_CANT_CREATE_FILE happens when the server cannot create a required file due to permissions, path, or disk problems. Fix it by granting correct filesystem rights, freeing space, or changing the data directory.
Can't create file '%s' (errno: %d - %s)
MySQL throws the message “Can't create file '%s' (errno: %d - %s)” when it cannot create or copy a file needed for an operation such as creating a table, copying a temporary file, or writing to the data directory.
The server aborts the statement and returns SQLSTATE HY000.
Fixing the underlying filesystem issue is mandatory because MySQL will keep failing on every attempt to touch the same path.
Insufficient filesystem permissions prevent the mysqld process from writing to the target directory.
SELinux or AppArmor policies can also block file creation.
A file with the same name already exists and is read-only, locking MySQL out of overwriting it.
Disk space or inode exhaustion on the partition that holds the data or temporary directory stops any new file from being created.
Invalid or non-existent paths in datadir, tmpdir, or TABLESPACE definitions lead MySQL to target locations that the OS rejects.
First, confirm the OS errno and descriptive string in the error message or server log.
They pinpoint whether the problem is permission-related, space-related, or path-related.
Grant mysqld ownership or at least read-write-execute rights on the data directory and target path. On Linux, chown mysql:mysql /var/lib/mysql && chmod 750 /var/lib/mysql resolves most permission issues.
If a file already exists, back it up and remove or rename it so CREATE TABLE or ALTER TABLE can proceed.
Free up space or move the data directory to a larger volume.
Verify df -h and df -i for disk space and inodes.
Update my.cnf tmpdir or datadir options to point to valid, writable locations, then restart MySQL.
CREATE TABLE failing inside a tablespace often signals a leftover .ibd file. Remove the orphan file and retry.
ALTER TABLE ... ALGORITHM=INPLACE can generate temporary files in tmpdir. Make tmpdir a writable directory with ample space or set tmpdir to /tmp in my.cnf.
mysqldump --single-transaction creates shadow tables.
Ensure the dump directory is writable or redirect with --result-file=FILE.
Run MySQL under a dedicated user that owns the data directory.
Keep permissions strict (750) but sufficient.
Monitor disk usage and inodes with cron jobs or Prometheus exporters to alert before reaching capacity.
Validate configuration paths after every change and use absolute paths in my.cnf.
Use Galaxy’s SQL editor to version and review DDL changes so accidental duplicate table creation is caught in code review, reducing leftover file conflicts.
Error 1030 ER_GET_ERRNO - Generic storage engine error often surfaces when 1004 escalates.
Check the same filesystem causes.
Error 1022 ER_DUP_KEY - Happens when a unique key conflict prevents table creation. Unlike 1004, it is schema-level, not filesystem-level.
Error 1016 ER_CANT_OPEN_FILE - Triggered when MySQL can’t open an existing file. Fix with similar permission and path checks.
.
The directory may still contain a hidden .frm or .ibd file or SELinux contexts prevent creation. Verify with ls -aZ and adjust policies.
Yes. Many DDL operations create temporary files in tmpdir. If tmpdir is read-only or full, 1004 appears. Point tmpdir to a writable partition.
Usually yes. Adjust permissions or free space and retry the statement. A restart is required only after changing datadir or tmpdir in my.cnf.
Galaxy versions DDL and exposes permissions issues during query reviews, alerting teams before they deploy changes that would hit 1004 in production.