SHOW SLAVE STATUS\G Last_Error: Relay log read failure: Could not parse relay log event entry. Possible reasons: 1. Master binlog corrupted 2. Slave relay log corrupted 3. Network problem 4. MySQL bug Slave_SQL_Running: No Last_SQL_Errno: 1594
經驗法則:Master Binlog 損壞極少見(可用 mysqlbinlog 驗證),網絡問題通常報連接錯誤,MySQL 5.1 確有同步 Bug 但多表現為此錯誤。**首選假設:Slave Relay Log 損壞**。
-- 從 SHOW SLAVE STATUS 獲取 Relay_Master_Log_File: mysql-bin.005121 -- Master 對應 Binlog 文件 Exec_Master_Log_Pos: 4 -- Master 對應 Position
STOP SLAVE;
CHANGE MASTER TO
MASTER_LOG_FILE = 'mysql-bin.005121',
MASTER_LOG_POS = 4;
START SLAVE;
SHOW SLAVE STATUS\G; -- 驗證 Slave_SQL_Running: Yes
CHANGE MASTER TO 會**刪除所有現有 Relay Log**,重新從 Master 指定位置拉取Exec_Master_Log_Pos 代表 SQL 線程已執行到的 Master 位置,作為安全恢復點mysqlbinlog /path/to/mysql-bin.005121 驗證可讀性SET GLOBAL sql_slave_skip_counter=1MySQL 5.1 複製模塊 Bug 密集(5.1.36 前尤甚)。**強烈建議升級至 5.1.40+ 或 5.1.37sp1**,修復大量同步穩定性問題。
#!/bin/bash
# 每分鐘檢查從庫狀態
STATUS=$(mysql -e "SHOW SLAVE STATUS\G" | grep -E "Slave_IO_Running|Slave_SQL_Running|Seconds_Behind_Master|Last_SQL_Errno")
if echo "$STATUS" | grep -q "No"; then
echo "$STATUS" | mail -s "MySQL Replication Alert" dba@company.com
fi