How to fix ERROR 1023: Error on close of file in MySQL

MySQLINTERMEDIATEHIGHUpdated Dec 22, 2025· 166 views

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.

Quick fix

Fixes 1023

df -h
  1. Check available disk space immediately
  2. Free disk space if needed
  3. Verify MySQL data directory permissions
  4. Check and increase file descriptor limits
mysql — error
df -h
ERROR 1023: Error on close of file

What this error means

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.

Typical symptoms

  • Queries fail with "ERROR 1023: Error on close of file"
  • MySQL becomes unstable after extended uptime with many operations
  • Disk space warnings appear in system logs alongside the 1023 error
  • Tables become marked as crashed or inaccessible
  • INSERT, UPDATE, or SELECT operations fail intermittently
  • MySQL daemon crashes or terminates unexpectedly

Common causes

  1. Disk is full or running critically low on free space (most common)
  2. File permissions on data directory or table files are incorrect (ownership issue)
  3. Operating system file descriptor limit (ulimit -n) is exceeded
  4. Network filesystem (NFS/SMB) connection issues causing timeout on close() calls
  5. Corrupted filesystem or bad sectors on disk
  6. Too many open files in MySQL (max open_files_limit reached)
  7. Temporary file location (/tmp) is full or inaccessible

How to fix "ERROR 1023: Error on close of file"

1Check available disk space immediately

Use df to check how much disk space is available on the partition containing your MySQL data directory:

bash
df -h

Look 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.

2Free disk space if needed

Stop MySQL to safely free disk space:

bash
sudo systemctl stop mysql

Delete old backups, logs, or temporary files on the same partition:

bash
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:

bash
sudo systemctl start mysql
3Verify MySQL data directory permissions

Check that the MySQL data directory is owned by the mysql user and has correct permissions:

bash
ls -ld /var/lib/mysql

Expected output: drwx------ 28 mysql mysql ...

If ownership is incorrect, fix it:

bash
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod 700 /var/lib/mysql

If individual table files have wrong permissions, MySQL cannot close them properly.

4Check and increase file descriptor limits

Check the current file descriptor limit:

bash
ulimit -n

For a busy MySQL server, this should be at least 10,000. If it's lower, increase it in /etc/security/limits.conf:

bash
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:

bash
sudo systemctl restart mysql
5Review MySQL error log for details

Check the MySQL error log for more information about which file failed to close:

bash
tail -100 /var/log/mysql/error.log

Or use MySQL to show the log location:

sql
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.

6Check for filesystem corruption (optional)

If errors persist after checking space and permissions, the filesystem itself may be corrupted. Check for errors:

bash
sudo fsck -n /dev/sdXY

Replace /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.

7Repair affected tables

After resolving the underlying filesystem issue, check if any tables became corrupted:

sql
CHECK TABLE your_table_name;

If a table is marked as crashed, repair it:

sql
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.

Advanced notes

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.

Frequently asked questions

What does "1023" mean?
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.
How do I fix "1023"?
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.
What causes "1023"?
Disk is full or running critically low on free space (most common) File permissions on data directory or table files are incorrect (ownership issue) Operating system file descriptor limit (ulimit -n) is exceeded
Is the "1023" 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