執行 service mysqld stop 報錯 MySQL manager or server PID file could not be found! [FAILED],實則 MySQL 進程仍在運行,PID 文件丟失或不匹配導致腳本誤判。本文提供標準排查與修復流程。
[root@centos var]# service mysqld stop
MySQL manager or server PID file could not be found! [FAILED]
檢查進程:
[root@irxpert-test /]# ps aux | grep mysq
root 10274 0.0 0.0 68160 1336 ? S 13:43 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/irxpert-test.pid
mysql 10353 0.0 1.0 344360 39464 ? Sl 13:43 0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/irxpert-test.err --pid-file=/var/lib/mysql/irxpert-test.pid
root 11884 0.0 0.0 63384 760 pts/1 S+ 15:44 0:00 grep mysq*
兩個 MySQL 進程(mysqld_safe 守護進程 + mysqld 主進程)仍在運行,但 PID 文件 /var/lib/mysql/irxpert-test.pid 可能被誤刪或內容不匹配。
kill 10274 # mysqld_safe
kill 10353 # mysqld
# 頑固進程用 kill -9
rm -f /var/lib/mysql/irxpert-test.pid
service mysqld start
# 或 systemctl start mysqld (CentOS 7+)
Starting MySQL. [ OK ]
kill -9 導致 mysqld 無法清理 PID 文件service mysqld stop / systemctl stop mysqld,避免直接 killpid-file 顯式指定路徑,確保目錄可寫、權限正確(mysql:mysql)Type=notify 內建 PID 追蹤#!/bin/bash
PID_FILE="/var/lib/mysql/$(hostname).pid"
if pgrep mysqld >/dev/null && [ ! -f "$PID_FILE" ]; then
echo "[$(date)] MySQL running but PID file missing, fixing..."
pkill -9 mysqld
pkill -9 mysqld_safe
rm -f "$PID_FILE"
systemctl start mysqld
fi
PID 文件異常是運維高頻小故障,建立標準化處理 SOP,能將故障恢復時間從分鐘級壓縮到秒級。