mysql is dead but subsys locked

mysql is dead but subsys locked

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

MySQL is Dead but Subsys Locked

Encountering the error mysql is dead but subsys locked after attempting to start or stop the MySQL service on RHEL is a classic symptom of a daemon state mismatch. This specific message indicates that while the main process has terminated, the system's init scripts (specifically SysVinit) believe the service is still running because the PID file has not been updated or cleaned up.

The root cause usually lies in how older RHEL versions, such as RHEL 5.0, manage process tracking. When a MySQL instance crashes unexpectedly or is killed via kill -9, the operating system does not automatically remove the Process ID (PID) file located at /var/run/mysqld/mysqld.pid. Subsequent attempts to start the service fail because the init script checks this stale PID file, assumes the daemon is active, and refuses to launch a new instance.

Diagnosing the Stale State

The error message Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' combined with the service failure suggests that the socket file is also missing or invalid, but the primary blocker is the locked state reported by the service manager.

To resolve this without guessing, you must verify the actual process status using standard Linux tools rather than relying on the init script's status output. Run the following command to see if any MySQL processes are actually consuming CPU or memory:

ps aux | grep mysqld

If the output is empty, the daemon is indeed dead, and the mysqld.pid file is simply out of sync with reality. You can confirm this by checking the existence of the PID file directly:

ls -l /var/run/mysqld/mysqld.pid

If the file exists but no process matches its ID, the system is in a "locked" state waiting for manual intervention.

Unlocking the Service

The standard procedure to clear this lock involves manually removing the stale PID file and the socket file (if they are corrupted or missing). Since MySQL stores temporary files like sockets in /var/run or /tmp, ensure you are targeting the correct directory based on your installation path.

Given that you installed MySQL in /usr/local/mysql/bin, the data directory might be different from the default /var/lib/mysql. Check where the socket is defined in your my.cnf. If it points to a location like /var/mysql/mysql.sock (as seen in your error message), ensure that directory exists and has the correct permissions.

Once you have identified the stale files, execute the following steps as root:

  1. Remove the PID file:

    rm -f /var/run/mysqld/mysqld.pid
    

    Note: Adjust the path if your configuration places the PID in /var/mysql or another custom location.

  2. Clean up the socket file:
    If the socket file at /var/mysql/mysql.sock does not exist, remove it so a new one can be generated upon startup. If it exists but is stale (often indicated by ownership issues), remove it:

    rm -f /var/mysql/mysql.sock
    
  3. Verify Data Directory Permissions:
    Ensure the MySQL user has write access to the data directory and the socket directory. Incorrect permissions here will prevent the daemon from starting even after unlocking the PID state.

Restarting the Service

After cleaning up the stale files, attempt to start the service again:

service mysqld start
# Or on newer systems using systemctl if available:
systemctl restart mysqld

The command should now return Started MySQL Server instead of FAILED. Your PHP script should subsequently be able to connect via the socket file.

Architectural Considerations for RHEL 5

It is worth noting that RHEL 5 uses SysVinit, which lacks the robustness of systemd regarding process tracking and unit locking. This behavior is a known limitation of that legacy release. Modern distributions typically handle these race conditions more gracefully, automatically cleaning up PID files on shutdown or crash. However, in environments constrained to older kernels, understanding the underlying file system state is critical for troubleshooting connectivity issues from within PHP applications.

If you are maintaining infrastructure where upgrading RHEL 5 is not an option, consider creating a wrapper script that checks process existence before attempting to start the service, preventing future FAILED states caused by zombie PID files. This manual oversight ensures deterministic behavior in legacy environments where automatic cleanup mechanisms are absent.

Our network