Error
Error Code:
1004
MariaDB Error 1004: File Creation Failed
Description
Error 1004 indicates that MariaDB was unable to create a file required for its operation. This can happen during various database activities, such as creating new tables, temporary files for sorting, or writing to log files, due to underlying system issues.
Error Message
Can't create file '%s' (errno: %d)
Known Causes
4 known causesInsufficient Directory Permissions
The MariaDB process does not have the necessary write permissions for the directory where it attempts to create the file.
Lack of Free Disk Space
The disk partition where MariaDB is trying to create the file has run out of available storage space.
Invalid File Path or Name
The specified path or filename for the file MariaDB is trying to create is either incorrect, too long, or contains invalid characters for the operating system.
Operating System Resource Limits
The operating system has reached its limit for the number of files (inodes) or processes that can be created, preventing MariaDB from creating new files.
Solutions
4 solutions available1. Free Up Disk Space easy
Clear disk space to allow file creation
1
Check available disk space
df -h /var/lib/mysql
2
Find large files in MySQL directory
sudo du -sh /var/lib/mysql/* | sort -hr | head -20
3
Purge old binary logs if enabled
PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 7 DAY);
4
Clean up old error logs
sudo truncate -s 0 /var/log/mysql/error.log
2. Fix Directory Permissions medium
Grant MariaDB write access to required directories
1
Check current ownership of MySQL data directory
ls -la /var/lib/mysql/
2
Fix ownership to mysql user
sudo chown -R mysql:mysql /var/lib/mysql/
sudo chmod 750 /var/lib/mysql/
3
Check tmpdir permissions
mysql -e "SHOW VARIABLES LIKE 'tmpdir';"
ls -la /tmp
4
Fix tmpdir permissions if needed
sudo chmod 1777 /tmp
3. Increase OS File Limits medium
Raise operating system limits for open files
1
Check current file limits for mysql user
sudo -u mysql bash -c 'ulimit -n'
2
Check system-wide inode usage
df -i /var/lib/mysql
3
Increase limits in /etc/security/limits.conf
mysql soft nofile 65535
mysql hard nofile 65535
4
For systemd, create override file
sudo mkdir -p /etc/systemd/system/mariadb.service.d/
echo -e '[Service]\nLimitNOFILE=65535' | sudo tee /etc/systemd/system/mariadb.service.d/limits.conf
sudo systemctl daemon-reload
sudo systemctl restart mariadb
4. Change tmpdir Location medium
Point MariaDB to a directory with more space
1
Create a new tmpdir with sufficient space
sudo mkdir -p /data/mysql-tmp
sudo chown mysql:mysql /data/mysql-tmp
sudo chmod 750 /data/mysql-tmp
2
Update MariaDB configuration
[mysqld]
tmpdir = /data/mysql-tmp
3
Restart MariaDB to apply changes
sudo systemctl restart mariadb