mysql 跳过同步错误sql_slave_skip_counter

来源:互联网 发布:网络词木马是什么意思 编辑:程序博客网 时间:2024/05/18 02:42

最近MySQL 遇到了同步问题,现整理一下常遇到的错误应急的解决方法,备用。

下边是应急方法,不在乎数据一致性。数据一致性要求高的不要用。或者临时用,记录下发生错误的表,等到业务不高时在进行数据表校验修复(修复方式请参见最后链接地址)。






方法一:手动设置动态参数 sql_slave_skip_counter


我常用的脚本:

stop slave sql_thread;set global sql_slave_skip_counter=1;start slave sql_thread;

这个要 根据具体的错误来判定,一般用于主键冲突或者更新失败错误,进行手动跳过。




方法二:静态服务器设置,需要重启mysql
[mysqld]
slave_skip_errors=1032,1062
重启MySQL之后,会自动加载配置文件,同步自动跳过更新,与主键冲突错误。
参数说明:
Normally, replication stops when an error occurs on the slave.
This gives you the opportunity to resolve the inconsistency in the data manually.
This variable tells the slave SQL thread to continue replication when a statement returns any of the errors listed in the variable value.


方法三:动态设置跳过错误
slave_exec_mode
这个比较狠
set global slave_exec_mode =strict;
严格执行策略。大多数情况下遇到错误,同步就会终止。等待错误解决。

set global slave_exec_mode =idempotent;
这个设置,可以允许同步跳过
duplicate-key and no-key-found错误




四、如果数据缺失严重,而且数据量很少的情况下,直接重做主从。




对于数据一致性要求较高的场合:主要针对1032(从库数据缺失)和1062主键冲突的错误、1452外键问题。参见下面链接

参看网址:http://www.linuxidc.com/Linux/2017-02/141059.htm

http://mp.weixin.qq.com/s/nRHk_idbH2xZPXepRolW9Q





原创粉丝点击