mysql从库在开启GTID时跳过错误的方法

未开启GTID的处理:

set global sql_slave_skip_counter=1;

如果开启了GTID,则会报错:

ERROR 1858 (HY000): sql_slave_skip_counter can not be set when the server is running with @@GLOBAL.GTID_MODE = ON. Instead, for each transaction that you want to skip, generate an empty transaction with the same GTID as the transaction

处理参考:

1、解析二进制日志,找出gtid点
mysqlbinlog --no-defaults cdbxxxxx_bin_mysqlbin.000002 > cdb002bin.sql
或通过下述sql查出:
select * from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER=1050;
1050为show SLAVE STATUS ; 查出的Last_Errno;

跳过报错gtid点,如果有多个,重复执行,注意不要搞错了!!
stop slave ;
set @@session.gtid_next='7661d18c-8e10-11e7-8e9c-6c0b84d5a868:298637';
begin;
commit;
set @@session.gtid_next=automatic;
start slave;

原创总结,多次实用验证,没毛病!


如果需要一次跳过多条,通过binlog找出需要跳过的gtid,批量执行:

set @@session.gtid_next='7661d18c-8e10-11e7-8e9c-6c0b84d5a868:298637'; begin; commit;
set @@session.gtid_next='7661d18c-8e10-11e7-8e9c-6c0b84d5a868:298638';begin;commit;
set @@session.gtid_next='7661d18c-8e10-11e7-8e9c-6c0b84d5a868:298639';begin;commit;
......
然后再
set @@session.gtid_next=automatic;
start slave;

即可。



你可能感兴趣的:(mysql)