当slave意外宕机时,有可能会损坏中继日志relay-log,再次开启同步复制时,会出现报错。
解决方法:找到同步的binlog日志和POS点,然后重新进行同步,这样就可以有新的中继日志了。
下边看个案例,模拟了中继日志损坏的情况,查看到的信息如下:
点击(此处)折叠或打开
公司主营业务:成都网站制作、网站建设、外贸网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出革吉免费做网站回馈大家。
-
MySQL> show slave status \G
-
ERROR 2006 (HY000): MySQL server has gone away
-
No connection. Trying to reconnect...
-
Connection id: 4
-
Current database: test
-
-
*************************** 1. row ***************************
-
Slave_IO_State: Waiting for master to send event
-
Master_Host: 10.10.10.200
-
Master_User: repl
-
Master_Port: 3306
-
Connect_Retry: 60
-
Master_Log_File: mysql-bin.000005
-
Read_Master_Log_Pos: 220
-
Relay_Log_File: mysql-relay-bin.000010
-
Relay_Log_Pos: 283
-
Relay_Master_Log_File: mysql-bin.000004
-
Slave_IO_Running: Yes
-
Slave_SQL_Running: No
-
Replicate_Do_DB:
-
Replicate_Ignore_DB:
-
Replicate_Do_Table:
-
Replicate_Ignore_Table:
-
Replicate_Wild_Do_Table:
-
Replicate_Wild_Ignore_Table:
-
Last_Errno: 1032
-
Last_Error: Could not execute Update_rows event on table test.test01; Can't find record in 'test01', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000004, end_log_pos 310
-
Skip_Counter: 0
-
Exec_Master_Log_Pos: 120
-
Relay_Log_Space: 2251
-
Until_Condition: None
-
Until_Log_File:
-
Until_Log_Pos: 0
-
Master_SSL_Allowed: No
-
Master_SSL_CA_File:
-
Master_SSL_CA_Path:
-
Master_SSL_Cert:
-
Master_SSL_Cipher:
-
Master_SSL_Key:
-
Seconds_Behind_Master: NULL
-
Master_SSL_Verify_Server_Cert: No
-
Last_IO_Errno: 0
-
Last_IO_Error:
-
Last_SQL_Errno: 1032
-
Last_SQL_Error: Could not execute Update_rows event on table test.test01; Can't find record in 'test01', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000004, end_log_pos 310
-
Replicate_Ignore_Server_Ids:
-
Master_Server_Id: 1
-
Master_UUID: 4adfcd1d-4059-11e7-9532-080027d597f9
-
Master_Info_File: mysql.slave_master_info
-
SQL_Delay: 0
-
SQL_Remaining_Delay: NULL
-
Slave_SQL_Running_State:
-
Master_Retry_Count: 86400
-
Master_Bind:
-
Last_IO_Error_Timestamp:
-
Last_SQL_Error_Timestamp: 170808 11:45:26
-
Master_SSL_Crl:
-
Master_SSL_Crlpath:
-
Retrieved_Gtid_Set:
-
Executed_Gtid_Set:
-
Auto_Position: 0
其中,涉及几个重要的参数:
slave_IO_Running:接受master的binlog的信息
master_Log_file:正在读取master上binlog日志名
Read_master_Log_Pos:正在读取master上当前binlog日志POS点。
slave_SQL_Running:执行写操作
Relay_master_Log_File:正在同步master上的binlog日志名。
Exec_master_Log_Pos:正在同步当前binlog日志的POS点。
以Relay_master_Log_File参数值和Exec_master_Log_Pos参数值为基准。
Relay_Log_File: mysql-relay-bin.000010
Relay_Log_Pos: 283
接下来开始重置主从复制:
-
mysql> stop slave;
-
Query OK, 0 rows affected (0.04 sec)
-
-
mysql> change master to master_log_file='mysql-relay-bin.000010',master_log_pos=283;
-
Query OK, 0 rows affected (0.06 sec)
-
-
mysql> start slave;
-
Query OK, 0 rows affected (0.12 sec)
通过这种方法可以修复中继日志,但是在MySQL5.5版本之后,在slave的my.cnf配置文件中加入relay_log_recovery=1就可以了。
文章名称:slave的中继日志relay-log损坏
URL链接:
http://cqcxhl.cn/article/gehpdo.html