我们有一个“ 1个主机,1个从机” MySQL设置。我们突然断电,使奴隶身亡。恢复机器后,我发现从机与主机不同步:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.1
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-log.001576
Read_Master_Log_Pos: 412565824
Relay_Log_File: mysqld-relay-bin.002671
Relay_Log_Pos: 6930
Relay_Master_Log_File: mysql-log.001573
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table: blah.table2
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1032
Last_Error: Could not execute Update_rows event on table blah.info; Can't find record in 'info', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-log.001573, end_log_pos 689031225
Skip_Counter: 0
Exec_Master_Log_Pos: 689030864
Relay_Log_Space: 2944772417
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 blah.info; Can't find record in 'info', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-log.001573, end_log_pos 689031225
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
我们使用的二进制日志格式为“ ROW”,因此当我尝试使用mysqlbinlog查看有问题的行时,我看不到任何用处。我不想简单地设置跳过计数器,因为我认为这会使我的表更加不同步。
我可以在从属服务器上做任何实质上可以“回滚”到给定时间点的事情,然后在其中我可以重置主日志号,位置等吗?如果没有,我可以做些什么来恢复同步?
通常可以使用pt-table-checksum和pt-table-sync从小的差异中恢复。
在我看来,当您的奴隶崩溃时,它在二进制日志序列中失去了位置。从服务器将其最后处理的binlog事件连续写入datadir / relay-log.info,但是此文件使用缓冲写操作,因此很容易在崩溃时丢失数据。
因此,Percona Server创建了crash-resistant replication功能以将相同的副本信息存储在InnoDB表中,以便从这种情况下恢复。
MySQL 5.6实现了similar feature:您可以设置relay_log_info_repository=TABLE
,以便副本以防崩溃的方式保存其状态。
发表您的评论:
是,在theory中,pt-table-sync可以修复任何数量的复制漂移,但这不一定是纠正较大差异的最有效方法。在某个时候,丢弃过时的副本并使用主服务器上的新备份重新初始化它更快,更有效。
签出How to setup a slave for replication in 6 simple steps with Percona Xtrabackup。