MySQL5.7延迟复制半同步复制
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.延迟复制
1>.什么是延迟复制
延迟复制是指定从库对主库的延迟至少是指定的这个间隔时间,默认是0秒。可以通过CHANGE MASTER TO命令来指定。例如:CHANGE MASTER TO MASTER_DELAY=N;其原理是从库收到主库的bin log之后,而是等待指定的秒数之后再执行。
mysql> mysql> show slave stATUS\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: node101.yinzhengjie.org.cn Master_User: copy Master_Port: 3306 Connect_Retry: 60 Master_Log_File: yinzhengjie-mysql-bin.000003 Read_Master_Log_Pos: 154 Relay_Log_File: node102-relay-bin.000006 Relay_Log_Pos: 391 Relay_Master_Log_File: yinzhengjie-mysql-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: 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: 154 Relay_Log_Space: 778 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: 0 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: 1 Master_UUID: b2127a6e-3cf8-11e9-ae0d-000c29fe9bef Master_Info_File: /yinzhengjie/softwares/mysql-5.7.25-linux-glibc2.12-x86_64/data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) mysql> mysql> STOP SLAVE; Query OK, 0 rows affected (0.00 sec) mysql> mysql> show slave stATUS\G *************************** 1. row *************************** Slave_IO_State: Master_Host: node101.yinzhengjie.org.cn Master_User: copy Master_Port: 3306 Connect_Retry: 60 Master_Log_File: yinzhengjie-mysql-bin.000003 Read_Master_Log_Pos: 154 Relay_Log_File: node102-relay-bin.000006 Relay_Log_Pos: 391 Relay_Master_Log_File: yinzhengjie-mysql-bin.000003 Slave_IO_Running: No 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: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 154 Relay_Log_Space: 778 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: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: b2127a6e-3cf8-11e9-ae0d-000c29fe9bef Master_Info_File: /yinzhengjie/softwares/mysql-5.7.25-linux-glibc2.12-x86_64/data/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: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) mysql> mysql> CHANGE MASTER TO MASTER_DELAY=5; Query OK, 0 rows affected (0.01 sec) mysql> mysql> START SLAVE; Query OK, 0 rows affected (0.00 sec) mysql> mysql> show slave stATUS\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: node101.yinzhengjie.org.cn Master_User: copy Master_Port: 3306 Connect_Retry: 60 Master_Log_File: yinzhengjie-mysql-bin.000003 Read_Master_Log_Pos: 154 Relay_Log_File: node102-relay-bin.000002 Relay_Log_Pos: 332 Relay_Master_Log_File: yinzhengjie-mysql-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: 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: 154 Relay_Log_Space: 541 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: 0 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: 1 Master_UUID: b2127a6e-3cf8-11e9-ae0d-000c29fe9bef Master_Info_File: /yinzhengjie/softwares/mysql-5.7.25-linux-glibc2.12-x86_64/data/master.info SQL_Delay: 5 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) mysql>