MySQL Error 4 (EE_BADCLOSE) occurs when the server fails to close a file or socket due to an underlying operating-system problem.
MySQL Error 4: EE_BADCLOSE occurs when the server cannot close a file or socket because the operating system returns an error. Verify disk space, file-descriptor limits, and permissions, then restart MySQL or repair the affected table to clear the condition.
Error on close of '%s' (OS errno %d - %s)
MySQL returns Error 4 with the symbolic name EE_BADCLOSE when it receives an operating-system error while trying to close a file or socket. The message template is “Error on close of '%s' (OS errno %d - %s)”.
The failure usually surfaces during intensive I/O operations such as writing to the data directory, rotating logs, or finishing a table repair.
Ignoring it risks data corruption or server crashes.
Operating systems raise close() errors when a file descriptor is invalid, the underlying storage is lost, or resources are exhausted. MySQL propagates that error as EE_BADCLOSE.
Frequent triggers include running out of disk space, exceeding open-file limits, unexpected network disconnects on sockets, or faulty storage devices that sporadically drop handles.
First read the associated OS errno in the error log.
Errno 28 signals no space left on device, while errno 24 points to too many open files. Address the underlying OS issue, then restart MySQL to release stale descriptors.
After the restart, run CHECK TABLE or REPAIR TABLE on objects mentioned in the log to confirm consistency.
Monitor the error log for a clean shutdown and startup.
Disk full - Free space or extend the partition, then flush logs and restart MySQL.
File-descriptor exhaustion - Increase open_files_limit in my.cnf and raise system limits via ulimit or systemd directives, then restart.
NFS or remote storage hiccups - Verify network stability, remount shares with hard,intr options, and consider local storage for critical paths.
Maintain at least 20 percent free disk space on data and log partitions.
Automate alerts in Prometheus or CloudWatch to catch low space early.
Set open_files_limit to a value greater than table_open_cache*2 and align system limits accordingly. Periodically run mysqladmin flush-hosts and flush-logs in maintenance windows.
Error 23 (EE_READ) appears when reads fail; causes overlap with EE_BADCLOSE when storage is corrupted. Fix storage first and run CHECK TABLE.
Error 28 (ER_GET_ERRNO) often accompanies EE_BADCLOSE when disk space is exhausted. Free space and restart to clear both.
.
Not always. It flags a close() failure, but data remains intact if the write completed. Still, run CHECK TABLE to be safe.
Sporadic entries during backups on busy servers may be benign, but recurring messages indicate a systemic resource issue and must be fixed.
Check the MySQL error log entry; the errno appears after the message. Use the strerror tool or man errno to decode it.
Galaxy’s editor tracks run history and error output, letting teams share remediation scripts and monitor fixes without copy-pasting SQL across tools.