mysql 5.6 从库主机断电重启导至从库不同步的解决办法

 

问题:  mysql 5.6 从库主机断电重启导至从库不同步了,

从库主机启动后执行:
start slave
show slave status\G

报错:
Last_Errno: 1594
Last_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.


解决办法:
1.在data库文件夹下找到 relay-log.info 文件,记录了正在执行的log-relay 文件名
如:
/home/app/mysql/data/relay-bin.002663
535371294
mysql-bin.000756
535371131


2. 找到该文件的下一个文件名查看
如:mysqlbinlog ./relay-bin.002664

查到如下内容:
Rotate to relay-bin.002665 pos: 4


3. 在从库上执行语句(master_ip换成主库ip):
change master to master_host='master_ip', master_user='repl', master_password='repl',master_log_file='relay-bin.002665',master_log_pos= 4;

再次启动:start slave
查看: show slave status\G
又出现报错:
Last_SQL_Errno: 1062
Last_SQL_Error: Could not execute Write_rows event on table mcr.tb_miss_voice; Duplicate entry '157938699' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000748, end_log_pos 32385


解决办法:
2.修改mysql的配置文件,通过slave_skip_errors参数来跳所有错误或指定类型的错误

vi /etc/my.cnf


[mysqld]
#跳过指定error no类型的错误
slave-skip-errors=1062,1032

#跳过所有错误
#slave-skip-errors=all

注意:
当配置文件里写两行:
slave-skip-errors=1062
slave-skip-errors=1032 时,第二个参数会覆盖第一个参数。所以一定要写到同一行,并用逗号分隔。


虽然slave会跳过这些错误,继续复制,但是仍会以Warning的形式记录到错误日志中,
如:

160620 10:40:17 [Warning] Slave SQL: Could not execute Write_rows event on table dba.t; Duplicate entry '10' for key 'PRIMARY',
Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000033, end_log_pos 1224, Error_code: 1062


重启Mysql服务

mysql.server restart

再次启动slave,
start slave;
show slave status\G

恢复正常同步

 

那些没有被复制的错误数据会输出到日志中

Error_code: 1062

Aug 16 17:44:53 mysql75 mysqld: 2017-08-16T09:44:53.142158Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15616-62' for key 'PRIMARY';, Error_code: 1062

Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.910737Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-84' for key 'PRIMARY';, Error_code: 1062

Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.911141Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-85' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.911918Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-87' for key 'PRIMARY';, Error_code: 1062

 

注意: master.info 和  relay-log.info 文件有可能在 my.cnf 中把 info 文件写在table 里,
my.cnf 中:

relay_log_info_repository = TABLE
master_info_repository = TABLE
relay_log_recovery = on

这样的话需要查表,因为data库文件夹下没有 master.info 和 relay-log.info 了
查询如下:

select * from mysql.slave_master_info;
select * from mysql.slave_relay_log_info;

这样和上边查看文件内容是一样的

posted @ 2020-01-06 14:34  莫让年华付水流  阅读(814)  评论(0编辑  收藏  举报