在修改延迟从库的master_delay数值的时候,仔细多看了一眼,发现设置新的master_delay之后,MySQL自动将从库的所有relay log清空,并重新生成,序号从000001开始,也就是把relay log全部删除了,并重新生成relay log。这样对于还没应用的relay log,会不会造成从库的数据丢失呢?下面用我的测试环境验证一下。
下面的这个从库准备修改master_delay,修改前这个从库的SQL_THREAD应用到了slave-relay-bin.000002的1316982,而IO_THREAD抽取到主库mysql-bin.000074的2688524,这是我的测试环境,我停止主库一切操作,防止主库生产新的binlog,当前这个从库是master_delay=3600:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.204.128
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000074
Read_Master_Log_Pos: 2688524
Relay_Log_File: slave-relay-bin.000002
Relay_Log_Pos: 1316982
Relay_Master_Log_File: mysql-bin.000074
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql,information_schema,performance_schema,sys
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 2638066
Relay_Log_Space: 1367647
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: 12
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 128
Master_UUID: f4859d1f-f82f-11e8-afbe-000c2999b048
Master_Info_File: /mysqlData/data/master.info
SQL_Delay: 3600
SQL_Remaining_Delay: 3588
Slave_SQL_Running_State: Waiting until MASTER_DELAY seconds after master executed event
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: f4859d1f-f82f-11e8-afbe-000c2999b048:101574-101575
Executed_Gtid_Set: 2b7ac8e6-f834-11e8-97d4-000c29d2f92c:1-11,
f4859d1f-f82f-11e8-afbe-000c2999b048:1-101574
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
查看当前relay log的最新位置是