第一步:停止sql_thread线程 stop slave sql_thread;
第二步:查找错误位置 show slave status \G;
Retrieved_Gtid_Set: 1864fb2f-54d7-11ed-81c4-000c2991c366:1-15 #当前io_thread已经接收到的binlog
Executed_Gtid_Set: 1864fb2f-54d7-11ed-81c4-000c2991c366:1-15,
59d4fb2f-54d8-11ed-8d61-000c29fb87c6:1-3 #当前从库sql_thread执行的二进制日志位置
第三步:将gtid分配给下一个事务 set gtid_next='59d4fb2f-54d8-11ed-8d61-000c29fb87c6:4'; #4=从库错误的当前位置+1
第四步:执行一个空事件 begin;commit;
第五步:设置系统自动分配gtid set gtid_next=automatic;
第六步:启动sql_thread线程 start slave sql_thread;
2、主从复制中断怎么解决
解决方案:从库复制中断要考虑两个线程:io_thread与sql_thread
io_thread:链接主库,接收binlog,写入relay-log,更新master.info
sql_thread:主要是因为逻辑不满足SQL执行,sql_thread回放是逻辑操作
案例:sql_thread停止。主库插入一条数据,但是从库已经有了这条记录
第一步:停止sql_thread线程 stop slave sql_thread;
第二步:查找错误指定的位置 show slave status \G;
第三步:主库服务器上的改动不记录binlog,不会复制到从库(关闭binlog日志) set sql_log_bin=0;
第四步:删除错误位置的数据 delete from tablename where id=从表已经有了的那条数据
第五步:恢复记录binlog并复制到从库(开启binlog日志) set sql_log_bin=1;
第六步:启动sql_thread线程 start salve sql_thread;