MySQL error 1023 indicates that the server failed to close a table, log, or temporary file, typically caused by disk space issues, file permission problems, or file descriptor limits. This guide shows how to diagnose the underlying filesystem problem and resolve it.
ERROR 1023 (SQLSTATE HY000, ER_ERROR_ON_CLOSE) occurs when the MySQL server attempts to close a file descriptor for a table, log, or temporary file, but the operating system returns an error. This error is almost always a symptom of an underlying filesystem problem rather than a MySQL configuration issue. The error message format is "Error on close of '%s' (errno: %d - %s)" where the values indicate which file failed to close and the OS-level error number. Common underlying causes include insufficient disk space, incorrect file permissions, hitting file descriptor limits, or network filesystem issues.
Use df to check how much disk space is available on the partition containing your MySQL data directory:
df -hLook for the partition containing your MySQL datadir (typically /var/lib/mysql or /usr/local/mysql/data). If used space is above 85% or available space is less than 1GB, you must free space immediately. This is the most common cause of error 1023.
Stop MySQL to safely free disk space:
sudo systemctl stop mysqlDelete old backups, logs, or temporary files on the same partition:
du -sh /path/to/mysql/datadir/*This shows the size of each database. Remove old databases or archived logs. Alternatively, add a new disk or mount a larger volume. Once you've freed space, restart MySQL:
sudo systemctl start mysqlCheck that the MySQL data directory is owned by the mysql user and has correct permissions:
ls -ld /var/lib/mysqlExpected output: drwx------ 28 mysql mysql ...
If ownership is incorrect, fix it:
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod 700 /var/lib/mysqlIf individual table files have wrong permissions, MySQL cannot close them properly.
Check the current file descriptor limit:
ulimit -nFor a busy MySQL server, this should be at least 10,000. If it's lower, increase it in /etc/security/limits.conf:
sudo bash -c 'echo "mysql soft nofile 10000" >> /etc/security/limits.conf'
sudo bash -c 'echo "mysql hard nofile 10000" >> /etc/security/limits.conf'Restart MySQL for the change to take effect:
sudo systemctl restart mysqlCheck the MySQL error log for more information about which file failed to close:
tail -100 /var/log/mysql/error.logOr use MySQL to show the log location:
SHOW VARIABLES LIKE 'log_error';Look for the specific filename mentioned in the error 1023 messages and any preceding OS-level errors (errno values). This helps identify if the problem is with a specific table or the temp directory.
If errors persist after checking space and permissions, the filesystem itself may be corrupted. Check for errors:
sudo fsck -n /dev/sdXYReplace /dev/sdXY with your actual partition. The -n flag does a read-only check without making changes. If errors are found, you may need to run fsck without -n (requires unmounting and downtime) or replace the disk. Consider backing up all data first.
After resolving the underlying filesystem issue, check if any tables became corrupted:
CHECK TABLE your_table_name;If a table is marked as crashed, repair it:
REPAIR TABLE your_table_name;For InnoDB tables, restart MySQL in recovery mode or use percona-xtrabackup to restore from backup if REPAIR doesn't work.
Error 1023 with errno 28 (No space left on device) requires immediate action—MySQL will crash if it cannot close files. For production systems, set up monitoring on disk usage and open file descriptors.
On NFS-mounted datadirs, timeout errors (errno 110) during close() calls indicate the NFS server is unresponsive or the network connection is unstable. Consider moving data to local SSD storage, tuning NFS mount options (rw,hard,timeo=180,retrans=3), or increasing MySQL's timeout handling.
MyISAM tables are particularly vulnerable to corruption from error 1023. InnoDB has better recovery via crash-recovery and redo logs, but still requires manual REPAIR. Always maintain current backups.
For systems approaching capacity, implement table partitioning to rotate old data to archived tables, use compression (InnoDB native or external tools), or implement data lifecycle policies to delete old records automatically.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL