一、基本环境
VMware10.0+CentOS6.9+MySQL5.7.19
| ROLE | HOSTNAME | BASEDIR | DATADIR | IP | PORT |
| M | ZST1 | /usr/local/mysql | /data/mysql/mysql3306/data | 192.168.85.132 | 3306 |
| S1 | ZST2 | /usr/local/mysql | /data/mysql/mysql3306/data | 192.168.85.133 | 3306 |
| S2 | ZST1 | /usr/local/mysql | /data/mysql/mysql3307/data | 192.168.85.132 | 3307 |
基于Row+Gtid搭建的一主两从异步复制结构:M->{S1、S2}。Binlog Server运行于192.168.85.133,日志保存目录/data/binlogserver
二、故障模拟
M不断地写入数据,分别暂停S1、S2的IO_Thread,然后shutdown主库,再启动S1、S2的IO_Thread。在完成上述操作后,我们来查看主、从数据情况
1、M不断地写入数据,分别暂停S1、S2的IO_Thread,然后shutdown主库 # 主库M在shutdown前的binlog及测试表中的数据 mydba@192.168.85.132,3306 [replcrash]> show master status; +------------------+----------+--------------+------------------+--------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+--------------------------------------------+ | mysql-bin.000064 | 1679 | | | 8ab82362-9c37-11e7-a858-000c29c1025c:1-493 | +------------------+----------+--------------+------------------+--------------------------------------------+ 1 row in set (0.00 sec) mydba@192.168.85.132,3306 [replcrash]> select * from repl; +----+----------+----------+ | id | name1 | name2 | +----+----------+----------+ | 1 | 16:12:59 | 16:12:59 | | 2 | 16:13:00 | 16:13:00 | | 3 | 16:13:03 | 16:13:03 | | 4 | 16:13:04 | 16:13:04 | | 5 | 16:13:06 | 16:13:06 | | 6 | 16:13:09 | 16:13:09 | | 7 | 16:13:10 | 16:13:10 | | 8 | 16:55:04 | 16:55:04 | | 9 | 17:01:05 | 17:01:05 | | 10 | 17:01:15 | 17:01:15 | | 11 | 17:02:15 | 17:02:15 | | 12 | 17:02:17 | 17:02:17 | | 13 | 17:04:01 | 17:04:01 | +----+----------+----------+ 13 rows in set (0.00 sec) mydba@192.168.85.132,3306 [replcrash]> shutdown; Query OK, 0 rows affected (0.01 sec) 2、再次启动S1、S2的IO_Thread # 从库S1复制状态 mydba@192.168.85.133,3306 [replcrash]> show slave status\G *************************** 1. row *************************** Slave_IO_State: Connecting to master Master_Host: 192.168.85.132 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000064 Read_Master_Log_Pos: 788 Relay_Master_Log_File: mysql-bin.000064 Slave_IO_Running: Connecting Slave_SQL_Running: Yes Exec_Master_Log_Pos: 788 Until_Condition: None Last_IO_Errno: 2003 Last_IO_Error: error connecting to master 'repl@192.168.85.132:3306' - retry-time: 60 retries: 1 Master_Server_Id: 1323306 Master_UUID: 8ab82362-9c37-11e7-a858-000c29c1025c SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Retrieved_Gtid_Set: 8ab82362-9c37-11e7-a858-000c29c1025c:166-490 Executed_Gtid_Set: 8ab82362-9c37-11e7-a858-000c29c1025c:1-490 Auto_Position: 1 # 从库S2复制状态 mydba@192.168.85.132,3307 [(none)]> show slave status\G *************************** 1. row *************************** Slave_IO_State: Connecting to master Master_Host: 192.168.85.132 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000064 Read_Master_Log_Pos: 1382 Relay_Master_Log_File: mysql-bin.000064 Slave_IO_Running: Connecting Slave_SQL_Running: Yes Exec_Master_Log_Pos: 1382 Until_Condition: None Last_IO_Errno: 2003 Last_IO_Error: error connecting to master 'repl@192.168.85.132:3306' - retry-time: 60 retries: 1 Master_Server_Id: 1323306 Master_UUID: 8ab82362-9c37-11e7-a858-000c29c1025c Master_Info_File: /data/mysql/mysql3307/data/master.info SQL_Delay: 60 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Retrieved_Gtid_Set: 8ab82362-9c37-11e7-a858-000c29c1025c:484-492 Executed_Gtid_Set: 8ab82362-9c37-11e7-a858-000c29c1025c:1-492,90b30799-9215-11e7-8645-000c29c1025c:1-6 Auto_Position: 1 # 从库S1的binlog及测试表中的数据 mydba@192.168.85.133,3306 [replcrash]> show master status; +------------------+----------+--------------+------------------+--------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+--------------------------------------------+ | mysql-bin.000001 | 5462247 | | | 8ab82362-9c37-11e7-a858-000c29c1025c:1-490 | +------------------+----------+--------------+------------------+--------------------------------------------+ 1 row in set (0.00 sec) mydba@192.168.85.133,3306 [replcrash]> select * from repl; +----+----------+----------+ | id | name1 | name2 | +----+----------+----------+ | 1 | 16:12:59 | 16:12:59 | | 2 | 16:13:00 | 16:13:00 | | 3 | 16:13:03 | 16:13:03 | | 4 | 16:13:04 | 16:13:04 | | 5 | 16:13:06 | 16:13:06 | | 6 | 16:13:09 | 16:13:09 | | 7 | 16:13:10 | 16:13:10 | | 8 | 16:55:04 | 16:55:04 | | 9 | 17:01:05 | 17:01:05 | | 10 | 17:01:15 | 17:01:15 | +----+----------+----------+ 10 rows in set (0.00 sec) # 从库S2的binlog及测试表中的数据 mydba@192.168.85.132,3307 [replcrash]> show master status; +------------------+----------+--------------+------------------+--------------------------------------------------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+--------------------------------------------------------------------------------------+ | mysql-bin.000008 | 2703 | | | 8ab82362-9c37-11e7-a858-000c29c1025c:1-492, 90b30799-9215-11e7-8645-000c29c1025c:1-6 | +------------------+----------+--------------+------------------+--------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) mydba@192.168.85.132,3307 [replcrash]> select * from repl; +----+----------+----------+ | id | name1 | name2 | +----+----------+----------+ | 1 | 16:12:59 | 16:12:59 | | 2 | 16:13:00 | 16:13:00 | | 3 | 16:13:03 | 16:13:03 | | 4 | 16:13:04 | 16:13:04 | | 5 | 16:13:06 | 16:13:06 | | 6 | 16:13:09 | 16:13:09 | | 7 | 16:13:10 | 16:13:10 | | 8 | 16:55:04 | 16:55:04 | | 9 | 17:01:05 | 17:01:05 | | 10 | 17:01:15 | 17:01:15 | | 11 | 17:02:15 | 17:02:15 | | 12 | 17:02:17 | 17:02:17 | +----+----------+----------+ 12 rows in set (0.00 sec)