MySQL主从故障汇总
故障现象一:Slave_IO_Running 为 NO
报错:
从库的 Slave_IO_Running 为 NO
The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).
问题分析:
主库和从库的 server-id 值一样。
解决方法:
修改从库的 server-id 的值,修改为和主库不一样,比主库低。修改完后重启,再同步即可
故障现象二:Slave_IO_Running 为 NO
报错:
从库的 Slave_IO_Running 为 NO
问题分析:
造成从库线程为 NO 的原因会有很多,主要原因是主键冲突或者主库删除或更新数据, 从库找不到记录,数据被修改导致。通常状态码报错有 1007、1032、1062、1452 等。
解决方法一:
mysql> stop slave;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> start slave;
解决方法二:
设置用户权限,设置从库只读权限
set global read_only=true;
故障现象三:Error initializing relay log position: I/O error reading the header from the binary log
报错:
Error initializing relay log position: I/O error reading the header from the binary log
分析问题:
从库的中继日志 relay-bin 损坏。
解决方法:
手工修复,重新找到同步的 binlog 和 pos 点,然后重新同步即可。
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.xxx',MASTER_LOG_POS=xxx;