问题-主从同步失败
今天线上环境MHA主从同步失败,特此记录。
首先检查从库的跟踪情况,show slave status\G
。
根据从库状态信息查询,在performance_schema.replication_applier_status_by_worker
查看详细信息。
select count(*) from performance_schema.replication_applier_status_by_worker;
select * from performance_schema.replication_applier_status_by_worker limit 1;
根据详细信息查看究竟是哪个SQL导致的同步失败,按需进行处理,以下提供几种处理方式:
跳过一条同步记录
stop slave;
set global sql_slave_skip_counter = 1;
start slave;
修改mysql的配置文件
通过slave_skip_errors
参数来跳所有错误或指定类型的错误
官方文档说明: slave_skip_errors
常见错误消息: 错误消息和常见问题
错误码查询:perror <error_core>
在[mysqld]
下面加入以下内容,请按需选择合适的配置
跳过指定类型的错误
# 这里列举一些常见错误
# 1032: 记录不存在
# 1053: 服务没有及时响应启动或控制请求
# 1062: 主键冲突
# 1064: 语法错误
# 1146: 表不存在
# 1396: 操作用户失败
slave-skip-errors=1032,1053,1062,1064,1146
跳过所有错误
slave-skip-errors=all
调整binlog跟随位置
查看主库情况:
show master status;
根据主库情况修改从库:
stop slave;
change master to master_host='{192.168.x.x}', master_user='{username}', master_password='{password}', master_log_file='{mysql-bin.000002}',master_log_pos={263};
start slave;
注意:
{}
内部是示例,需要按需进行调整。
问题-主从同步失败
https://blog.cikaros.top/doc/d0620a9f.html