Common SQL Errors

MySQL Error 4: EE_BADCLOSE - How to Fix File Close Failures

Galaxy Team
August 5, 2025

MySQL Error 4 (EE_BADCLOSE) occurs when the server fails to close a file or socket due to an underlying operating-system problem.

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 4 (EE_BADCLOSE)?

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 Highlights

Typical Error Message

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

Error Type

File I/O Error

Language

MySQL

Symbol

EE_BADCLOSE

Error Code

4

SQL State

Explanation

Table of Contents

What is MySQL Error 4 (EE_BADCLOSE)?

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.

What Causes This Error?

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.

How to Fix MySQL Error 4: EE_BADCLOSE

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.

Common Scenarios and Solutions

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.

Best Practices to Avoid This Error

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.

Related Errors and Solutions

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.

.

Common Causes

Related Errors

FAQs

Does EE_BADCLOSE always mean data is corrupted?

Not always. It flags a close() failure, but data remains intact if the write completed. Still, run CHECK TABLE to be safe.

Can I ignore occasional EE_BADCLOSE entries?

Sporadic entries during backups on busy servers may be benign, but recurring messages indicate a systemic resource issue and must be fixed.

How do I find the OS errno?

Check the MySQL error log entry; the errno appears after the message. Use the strerror tool or man errno to decode it.

How does Galaxy help?

Galaxy’s editor tracks run history and error output, letting teams share remediation scripts and monitor fixes without copy-pasting SQL across tools.

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