非 GTID 模式,主库故障导致从库接收到不完整的事务时,Read_Master_Log_Pos ≠ Exec_Master_Log_Pos
此时可以通过下面方法判定本地已经回放完成
检查 MySQL 从库的复制状态,通过查询 SHOW PROCESSLIST 命令的结果,判断从库是否处于以下正常等待状态之一:
SHOW PROCESSLIST
MySQL 5.6 及之前版本: "Has read all relay log; waiting for the slave I/O thread to update it"
"Has read all relay log; waiting for the slave I/O thread to update it"
MySQL 5.6: "Slave has read all relay log; waiting for the slave I/O thread to update it"
"Slave has read all relay log; waiting for the slave I/O thread to update it"
MySQL 8.0: "Replica has read all relay log; waiting for more updates"
"Replica has read all relay log; waiting for more updates"
如果检测到上述任一状态,返回 0(表示复制正常等待);否则返回 -1(表示异常或未检测到目标状态)。
0
-1
看 5.7 的processlist 里是 "Slave has read all relay log; waiting for more updates"
Last updated 4 months ago