萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 資料庫 >> MySQL 教學

MySQL 主從同步報錯 Failed to initialize the master info structure 徹底排查

錯誤現場

從庫 show slave status \G 顯示 Slave_IO_Running: No,執行 start slave 報錯:

ERROR 1201 (HY000): Could not initialize master info structure;
more error messages can be found in the MySQL error log

常規三步走(網上通用方案)

STOP SLAVE;
RESET SLAVE;
CHANGE MASTER TO 
  MASTER_HOST='192.168.1.100',
  MASTER_PORT=3306,
  MASTER_USER='repl',
  MASTER_PASSWORD='repl',
  MASTER_LOG_FILE='mysql-bin.000051',
  MASTER_LOG_POS=254105;
START SLAVE;

若仍報錯,需深入錯誤日志。

錯誤日志關鍵線索

160324 6:40:10 [ERROR] log *** glibc detected *** /data/mysql/bin/mysqld: 
corrupted double-linked list: 0x00002ab038100ab0 ***
listed in the index, but failed to stat
160324 6:40:10 [ERROR] Error counting relay log space
160324 6:40:10 [ERROR] Failed to initialize the master info structure

關鍵字:corrupted double-linked list、failed to stat、relay log space。

根因定位:relay-bin.index 索引文件損壞

檢查數據目錄下 主機名-relay-bin.index(如 Centos64-relay-bin.index),正常應列出 relay log 文件名:

./Centos64-relay-bin.002064
./Centos64-relay-bin.002065
./Centos64-relay-bin.002066
...

實際發現文件內容異常(被寫入了錯誤的二進制數據或截斷)。

修復步驟

  1. 備份並移除損壞的索引文件:
    cd /data/mysql/data
    mv Centos64-relay-bin.index Centos64-relay-bin.index.bak
  2. 重啟 MySQL 服務(MySQL 會自動重建索引文件)。
  3. 重新執行常規三步走:
    STOP SLAVE;
    RESET SLAVE;
    CHANGE MASTER TO ...;
    START SLAVE;
  4. 驗證:SHOW SLAVE STATUS \G 確認 Slave_IO_Running: Yes、Slave_SQL_Running: Yes。

易損文件清單(遇到類似問題優先檢查)

  • mysql-bin.index(主庫二進制日志索引)
  • relay-log.info(從庫中繼日志信息)
  • 主機名-relay-bin.index(從庫中繼日志索引)
  • master.info(舊版本主庫信息)

這些文件損壞時,重命名或移走後重啟 MySQL,再重新配置主從通常能解決。

copyright © 萬盛學電腦網 all rights reserved