Common SQL Errors

MySQL Error 1023: ER_ERROR_ON_CLOSE - How to Diagnose, Fix, and Prevent

Galaxy Team
August 5, 2025

MySQL cannot close a file descriptor after writing, usually due to file-system, permission, or hardware problems.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1023 ER_ERROR_ON_CLOSE?

MySQL Error 1023: ER_ERROR_ON_CLOSE signals that the server failed to close a table, log, or temporary file. Check disk space, file permissions, and operating-system error logs; then repair or move the affected files to clear the error.

Error Highlights

Typical Error Message

Error on close of '%s' (errno: %d - %s)

Error Type

File System Error

Language

MySQL

Symbol

ER_ERROR_ON_CLOSE

Error Code

1023

SQL State

Explanation

Table of Contents

What is MySQL error 1023 ER_ERROR_ON_CLOSE?

Error 1023 appears as: ERROR 1023 (HY000): Error on close of '%s' (errno: %d - %s). MySQL reports it when the operating system returns an error while the server tries to close a file descriptor for a table, log, or temporary file.

The condition usually points to a file-system problem such as insufficient space, missing permissions, or a damaged disk.

Fixing it quickly prevents data loss and avoids server shutdowns.

What Causes This Error?

The server raises ER_ERROR_ON_CLOSE when the close() system call fails. MySQL surfaces the OS errno and message, letting you trace the root cause directly to file-system issues, quota limits, or hardware faults.

Affected operations include ALTER TABLE, large inserts, log rotation, and temporary table flushes.

If MySQL cannot close its file handle, it may mark the table as crashed and block subsequent queries.

How to Fix MySQL Error 1023

Identify the failing filename in the error, then inspect the corresponding directory. Confirm available disk space with df -h, file descriptors with lsof, and permissions with ls -l. Correct any anomalies and restart the server only if necessary.

Run CHECK TABLE or REPAIR TABLE on MyISAM tables, or ANALYZE TABLE for InnoDB.

If the file is beyond repair, rename or move it out of the data directory so MySQL can recreate it on startup.

Common Scenarios and Solutions

Disk full errors often accompany ER_ERROR_ON_CLOSE. Free space or mount a larger volume, then retry the query. Permission issues arise after manual file copies; reset ownership to the MySQL user.

On network file systems, intermittent IO failures can trigger the error.

Move the data directory to local storage or tune NFS options for stability.

Best Practices to Avoid This Error

Monitor disk usage, inode counts, and open file descriptors. Configure ulimit -n high enough for busy servers.

Schedule log rotations off-peak to reduce contention.

Using Galaxy’s desktop SQL editor, you can store vetted maintenance queries such as disk-usage checks in shared Collections, ensuring every engineer can diagnose and resolve file-system issues swiftly.

Related Errors and Solutions

Errors 23 (ERRNO 23 - File table overflow) and 24 (ERRNO 24 - Too many open files) often precede 1023.

Increasing open_files_limit and OS file-handle limits resolves them.

Error 1016 (HY000 - Can't open file) indicates MySQL cannot open rather than close a file. Causes and fixes overlap but focus on access permissions.

.

Common Causes

Disk Full

No free space or exhausted inodes prevent MySQL from closing and flushing file buffers.

Permission or Ownership Mismatch

Files created manually or restored from backups may not belong to the MySQL user, blocking close operations.

Hardware or File-System Corruption

Bad sectors, failing SSDs, or corrupted ext4/XFS metadata cause kernel errors returned to MySQL.

Network File System Glitches

NFS timeouts or SMB disconnects interrupt close() calls on remote storage.

Open File Descriptor Exhaustion

Hitting OS or MySQL open_files_limit keeps descriptors in limbo, making subsequent close attempts fail.

.

Related Errors

FAQs

Does Error 1023 corrupt my data?

Usually no, but it can mark MyISAM tables as crashed. Run CHECK TABLE or restore from backup to be safe.

Can I ignore ER_ERROR_ON_CLOSE if queries still run?

Ignoring it risks sudden crashes or data loss. Always resolve the root file-system cause quickly.

Is a server restart required?

Only if MySQL hangs or you moved corrupted files. Otherwise fix permissions, free space, and issue FLUSH TABLES.

How does Galaxy help?

Galaxy lets teams store, version, and share maintenance queries. Everyone can quickly run disk and table-health checks without hunting for scripts.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo