好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

MySQL复制应用中继日志解析

> select * from table_pk; +-----+-----------+-----+-----+ | id | name | age | sex | +-----+-----------+-----+-----+ | 111 | zhangsan | 20 | 0 | | 222 | lisi | 22 | 1 | | 333 | wangwu | 22 | 1 | | 444 | lilei | 32 | 0 | | 555 | hanmeimei | 30 | 1 | +-----+-----------+-----+-----+ 5 rows in set ( 0.00 sec) (dg6)root@localhost [mytest] > show global variables like ‘ %binlog_format% ‘ ; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set ( 0.00 sec)


那么我们去从库看看

(dg7)root@localhost [mytest]>  select  *  from table_pk;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | zhangsan  |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | wangwu    |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
+-----+-----------+-----+-----+
 5  rows  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > show global variables like  ‘  %binlog_format%  ‘  ;
 +--------------------------+-------------------+
| Variable_name            | Value             |
+--------------------------+-------------------+
| binlog_format            | ROW               |
+--------------------------+-------------------+
 8  rows  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] >  show slave status\G
 ***************************  1 . row *************************** 
               Slave_IO_State: Waiting   for   master to send event
                  Master_Host:   192.168 . 80.106  
                  Master_User: repl
                  Master_Port:   3306  
                Connect_Retry:   60  
              Master_Log_File: dg6 -logbin. 000001  
          Read_Master_Log_Pos:   4469  
               Relay_Log_File: dg7 -relay-bin. 000002  
                Relay_Log_Pos:   4681  
        Relay_Master_Log_File: dg6 -logbin. 000001  
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql
           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:   4469  
              Relay_Log_Space:   4883  
              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: b888e1ea - 9739 -11e4-a24e- 000c29b24887
             Master_Info_File:  /data/mydata/master. info  
                    SQL_Delay:   0  
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting   for  the slave I/ O thread to update it
           Master_Retry_Count:   86400  
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 17  
            Executed_Gtid_Set: a9926b45 -975d-11e4-a339-000c29b24888: 1 - 9  ,
b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 17  
                Auto_Position:   1 
 1  row  in  set ( 0.00  sec)

数据是复制过来的,MySQL主从复制是正常的,那么我们为了验证MySQL复制SQL线程是居于刚才那张图的流程,有主键,就按主键更新匹配更新记录。

那么我们在从库修改一行数据,故意制造不一致。
  

(dg7)root@localhost [mytest]> UPDATE `table_pk` SET `name`= ‘  laowang  ‘  WHERE ` id `= 333;  
Query OK,   0  rows affected ( 0.00   sec)
Rows matched:   1   Changed:  0   Warnings:  0  

(dg7)root@localhost [mytest] >  select  *  from table_pk;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | zhangsan  |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | laowang   |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
+-----+-----------+-----+-----+
 5  rows  in  set ( 0.00  sec)


这时候主从数据不一致了

 主库
(dg6)root@localhost [mytest] >  select  * from table_pk where  id = 333  ;
 +-----+--------+-----+-----+
|  id   | name   | age | sex |
+-----+--------+-----+-----+
|  333  | wangwu |   22  |    1  |
+-----+--------+-----+-----+
 1  row  in  set ( 0.00   sec)

从库

(dg7)root@localhost [mytest] >  select  * from table_pk where  id = 333  ;
 +-----+---------+-----+-----+
|  id   | name    | age | sex |
+-----+---------+-----+-----+
|  333  | laowang |   22  |    1  |
+-----+---------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > 


那么,我们在主库更新一行数据。

(dg6)root@localhost [mytest]> UPDATE `table_pk` SET `name`= ‘  wangzi  ‘  WHERE ` id `= 333  ;
Query OK,   1  row affected ( 0.01   sec)
Rows matched:   1   Changed:  1   Warnings:  0  

(dg6)root@localhost [mytest] >  select  * from table_pk where  id = 333  ;
 +-----+--------+-----+-----+
|  id   | name   | age | sex |
+-----+--------+-----+-----+
|  333  | wangzi |   22  |    1  |
+-----+--------+-----+-----+
 1  row  in  set ( 0.00  sec)


我们来看一下从库状态,是不是主库的更新给复制过来了,见证奇迹的时候到了

###############################################
(dg7)root@localhost [mytest]> select * from table_pk where id = 333 ; +-----+---------+-----+-----+ | id | name | age | sex | +-----+---------+-----+-----+ | 333 | laowang | 22 | 1 | +-----+---------+-----+-----+ 1 row in set ( 0.00 sec)
######################### 神奇的是主库的更新过来了############################################# (dg7)root@localhost [mytest] > select * from table_pk where id = 333 ; +-----+--------+-----+-----+ | id | name | age | sex | +-----+--------+-----+-----+ | 333 | wangzi | 22 | 1 | +-----+--------+-----+-----+ 1 row in set ( 0.00 sec)
#########################那么看一下MySQL主从复制状态看看,也是正常的###################### (dg7)root@localhost [mytest] > show slave status\G *************************** 1 . row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168 . 80.106 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: dg6 -logbin. 000001 Read_Master_Log_Pos: 5249 Relay_Log_File: dg7 -relay-bin. 000002 Relay_Log_Pos: 5461 Relay_Master_Log_File: dg6 -logbin. 000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: mysql 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: 5249 Relay_Log_Space: 5663 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: b888e1ea - 9739 -11e4-a24e- 000c29b24887 Master_Info_File: /data/mydata/master. info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/ O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 20 Executed_Gtid_Set: a9926b45 -975d-11e4-a339-000c29b24888: 1 - 11 , b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 20 Auto_Position: 1 1 row in set ( 0.00 sec) (dg7)root@localhost [mytest] >


3.验证没有索引的情况

 主库创建表和插入记录

  CREATE TABLE `table_index` (
  `  id `  int ( 11  ) NOT NULL,
  `name` varchar(  20  ) NOT NULL,
  `age` tinyint(  4  ) NOT NULL,
  `sex` tinyint(  4 ) NOT NULL COMMENT  ‘  0,man,1,woman  ‘  ,
  ) ENGINE = InnoDB 

(dg6)root@localhost [mytest] >  select  *  from table_index;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | zhangsan  |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | wangwu    |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
+-----+-----------+-----+-----+
 5  rows  in  set ( 0.00   sec)

(dg6)root@localhost [mytest] > 


从库看看

(dg7)root@localhost [mytest]>  select  *  from table_index;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | zhangsan  |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | wangwu    |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
+-----+-----------+-----+-----+
 5  rows  in  set ( 0.00  sec)

我们在从库继续搞破坏,把age为22的记录修改为laowang,这时候主从已经不一致了。

(dg7)root@localhost [mytest]>  select  * from table_index where age= ‘  22  ‘  ;
 +-----+--------+-----+-----+
|  id   | name   | age | sex |
+-----+--------+-----+-----+
|  333  | wangwu |   22  |    1  |
+-----+--------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > update table_index set name= ‘  laowang  ‘  where age= 22  ;
Query OK,   1  row affected ( 0.01   sec)
Rows matched:   1   Changed:  1   Warnings:  0  

(dg7)root@localhost [mytest] >  select  * from table_index where age= 22  ;
 +-----+---------+-----+-----+
|  id   | name    | age | sex |
+-----+---------+-----+-----+
|  333  | laowang |   22  |    1  |
+-----+---------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > 

 

那么我们还是在主库更新一下记录。

(dg6)root@localhost [mytest]>  select  * from table_index where name= ‘  lisi  ‘  ;
 +-----+------+-----+-----+
|  id   | name | age | sex |
+-----+------+-----+-----+
|  222  | lisi |   22  |    1  |
+-----+------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg6)root@localhost [mytest] >  update table_index set age= 30  where name= ‘  lisi  ‘  ;
Query OK,   1  row affected ( 0.01   sec)
Rows matched:   1   Changed:  1   Warnings:  0  

(dg6)root@localhost [mytest] >  select  * from table_index where name= ‘  lisi  ‘  ;
 +-----+------+-----+-----+
|  id   | name | age | sex |
+-----+------+-----+-----+
|  222  | lisi |   30  |    1  |
+-----+------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg6)root@localhost [mytest] > 

 

回到从库看看,数据没有更新过来,主从复制也是异常的

(dg7)root@localhost [mytest]>  select  * from table_index where name= ‘  lisi  ‘  ;
 +-----+------+-----+-----+
|  id   | name | age | sex |
+-----+------+-----+-----+
|  222  | lisi |   33  |    1  |
+-----+------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] >  show slave status\G
 ***************************  1 . row *************************** 
               Slave_IO_State: Waiting   for   master to send event
                  Master_Host:   192.168 . 80.106  
                  Master_User: repl
                  Master_Port:   3306  
                Connect_Retry:   60  
              Master_Log_File: dg6 -logbin. 000001  
          Read_Master_Log_Pos:   7376  
               Relay_Log_File: dg7 -relay-bin. 000003  
                Relay_Log_Pos:   724  
        Relay_Master_Log_File: dg6 -logbin. 000001  
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql
           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 mytest.table_index; Can  ‘  t find record in   ‘ table_index ‘  , Error_code: 1032; Corrupted replication event was detected, Error_code: 1610; handler error HA_ERR_END_OF_FILE; the event  ‘ s master log dg6-logbin. 000001 , end_log_pos  7345  
                 Skip_Counter:   0  
          Exec_Master_Log_Pos:   7112  
              Relay_Log_Space:   8090  
              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 mytest.table_index; Can  ‘  t find record in   ‘ table_index ‘  , Error_code: 1032; Corrupted replication event was detected, Error_code: 1610; handler error HA_ERR_END_OF_FILE; the event  ‘ s master log dg6-logbin. 000001 , end_log_pos  7345  
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id:   1  
                  Master_UUID: b888e1ea - 9739 -11e4-a24e- 000c29b24887
             Master_Info_File:  /data/mydata/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:   150425   08 : 30 : 49  
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 28  
            Executed_Gtid_Set: a9926b45 -975d-11e4-a339-000c29b24888: 1 - 14  ,
b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 27  
                Auto_Position:   1 
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > 

 

4.验证有唯一索引情况

 

测试方法都一样,下面步骤我都就贴结果了。

(dg6)root@localhost [mytest]>  select  *  from table_index;
 +-----+-----+-----------+-----+-----+
|  id   | sid | name      | age | sex |
+-----+-----+-----------+-----+-----+
|  111  |    1  | zhangsan  |   20  |    0  |
|  222  |    2  | lisi      |   30  |    1  |
|  333  |    3  | wangzi    |   22  |    1  |
|  444  |    4  | lilei     |   32  |    0  |
|  555  |    5  | hanmeimei |   30  |    1  |
+-----+-----+-----------+-----+-----+
 5  rows  in  set ( 0.00   sec)

(dg6)root@localhost [mytest] >  select  * from table_index where sid= 3  ;
 +-----+-----+--------+-----+-----+
|  id   | sid | name   | age | sex |
+-----+-----+--------+-----+-----+
|  333  |    3  | wangzi |   22  |    1  |
+-----+-----+--------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg6)root@localhost [mytest] > update table_index set name= ‘  wangwu  ‘  where sid= 3  ;
Query OK,   1  row affected ( 0.00   sec)
Rows matched:   1   Changed:  1   Warnings:  0  

(dg6)root@localhost [mytest] >  select  * from table_index where sid= 3  ;
 +-----+-----+--------+-----+-----+
|  id   | sid | name   | age | sex |
+-----+-----+--------+-----+-----+
|  333  |    3  | wangwu |   22  |    1  |
+-----+-----+--------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg6)root@localhost [mytest] > 

从库看看,能更新过来,而且主从复制状态是正常的

(dg7)root@localhost [mytest]>  select  *  from table_index;
 +-----+-----+-----------+-----+-----+
|  id   | sid | name      | age | sex |
+-----+-----+-----------+-----+-----+
|  111  |    1  | zhangsan  |   20  |    0  |
|  222  |    2  | lisi      |   30  |    1  |
|  333  |    3  | wangzi    |   22  |    1  |
|  444  |    4  | lilei     |   32  |    0  |
|  555  |    5  | hanmeimei |   30  |    1  |
+-----+-----+-----------+-----+-----+
 5  rows  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > update table_index set name= ‘  laowang  ‘  where sid= 3  ;
Query OK,   1  row affected ( 0.01   sec)
Rows matched:   1   Changed:  1   Warnings:  0  

(dg7)root@localhost [mytest] >  select  * from table_index where sid= 3  ;
 +-----+-----+---------+-----+-----+
|  id   | sid | name    | age | sex |
+-----+-----+---------+-----+-----+
|  333  |    3  | laowang |   22  |    1  |
+-----+-----+---------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] >  show slave status\G
 ***************************  1 . row *************************** 
               Slave_IO_State: Waiting   for   master to send event
                  Master_Host:   192.168 . 80.106  
                  Master_User: repl
                  Master_Port:   3306  
                Connect_Retry:   60  
              Master_Log_File: dg6 -logbin. 000001  
          Read_Master_Log_Pos:   13038  
               Relay_Log_File: dg7 -relay-bin. 000005  
                Relay_Log_Pos:   5841  
        Relay_Master_Log_File: dg6 -logbin. 000001  
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql
           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:   13038  
              Relay_Log_Space:   6615  
              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: b888e1ea - 9739 -11e4-a24e- 000c29b24887
             Master_Info_File:  /data/mydata/master. info  
                    SQL_Delay:   0  
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting   for  the slave I/ O thread to update it
           Master_Retry_Count:   86400  
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 52  
            Executed_Gtid_Set: a9926b45 -975d-11e4-a339-000c29b24888: 1 - 26  ,
b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 52  
                Auto_Position:   1 
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] >  select  * from table_index where sid= 3  ;
 +-----+-----+--------+-----+-----+
|  id   | sid | name   | age | sex |
+-----+-----+--------+-----+-----+
|  333  |    3  | wangwu |   22  |    1  |
+-----+-----+--------+-----+-----+
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] >  show slave status\G
 ***************************  1 . row *************************** 
               Slave_IO_State: Waiting   for   master to send event
                  Master_Host:   192.168 . 80.106  
                  Master_User: repl
                  Master_Port:   3306  
                Connect_Retry:   60  
              Master_Log_File: dg6 -logbin. 000001  
          Read_Master_Log_Pos:   13302  
               Relay_Log_File: dg7 -relay-bin. 000005  
                Relay_Log_Pos:   6105  
        Relay_Master_Log_File: dg6 -logbin. 000001  
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql
           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:   13302  
              Relay_Log_Space:   6879  
              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: b888e1ea - 9739 -11e4-a24e- 000c29b24887
             Master_Info_File:  /data/mydata/master. info  
                    SQL_Delay:   0  
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting   for  the slave I/ O thread to update it
           Master_Retry_Count:   86400  
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 53  
            Executed_Gtid_Set: a9926b45 -975d-11e4-a339-000c29b24888: 1 - 26  ,
b888e1ea - 9739 -11e4-a24e-000c29b24887: 1 - 53  
                Auto_Position:   1 
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > 

5.验证有主键和有普通索引情况

(dg6)root@localhost [mytest]>  select  *  from table_key;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | zhangsan  |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | wangwu    |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
|  666  | lucy      |   30  |    1  |
|  777  | lili      |   30  |    1  |
|  888  | lintao    |   32  |    0  |
+-----+-----------+-----+-----+
 8  rows  in  set ( 0.00   sec)

(dg6)root@localhost [mytest] > update table_key set name= ‘  zhangsir  ‘  where age= 20  ;
Query OK,   1  row affected ( 0.01   sec)
Rows matched:   1   Changed:  1   Warnings:  0  

(dg6)root@localhost [mytest] >  select  *  from table_key;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | zhangsir  |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | wangwu    |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
|  666  | lucy      |   30  |    1  |
|  777  | lili      |   30  |    1  |
|  888  | lintao    |   32  |    0  |
+-----+-----------+-----+-----+
 8  rows  in  set ( 0.00   sec)

(dg6)root@localhost [mytest] > 

从库看看

(dg7)root@localhost [mytest]>  select  *  from table_key;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | zhangsan  |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | wangwu    |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
|  666  | lucy      |   30  |    1  |
|  777  | lili      |   30  |    1  |
|  888  | lintao    |   32  |    0  |
+-----+-----------+-----+-----+
 8  rows  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > desc update table_key set name= ‘  xiaozhang  ‘  where age= 20  ;
 +----+-------------+-----------+-------+---------------+-----------+---------+-------+------+-------------+
|  id  | select_type | table     | type  | possible_keys | key       | key_len | ref   | rows | Extra       |
+----+-------------+-----------+-------+---------------+-----------+---------+-------+------+-------------+
|   1  | SIMPLE      | table_key | range | age_index     | age_index |  1        | const |     1  | Using where |
+----+-------------+-----------+-------+---------------+-----------+---------+-------+------+-------------+
 1  row  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] > update table_key set name= ‘  xiaozhang  ‘  where age= 20  ;
Query OK,   1  row affected ( 0.03   sec)
Rows matched:   1   Changed:  1   Warnings:  0  

(dg7)root@localhost [mytest] >  select  *  from table_key;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | xiaozhang |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | wangwu    |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
|  666  | lucy      |   30  |    1  |
|  777  | lili      |   30  |    1  |
|  888  | lintao    |   32  |    0  |
+-----+-----------+-----+-----+
 8  rows  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] >  select  *  from table_key;
 +-----+-----------+-----+-----+
|  id   | name      | age | sex |
+-----+-----------+-----+-----+
|  111  | zhangsir  |   20  |    0  |
|  222  | lisi      |   22  |    1  |
|  333  | wangwu    |   22  |    1  |
|  444  | lilei     |   32  |    0  |
|  555  | hanmeimei |   30  |    1  |
|  666  | lucy      |   30  |    1  |
|  777  | lili      |   30  |    1  |
|  888  | lintao    |   32  |    0  |
+-----+-----------+-----+-----+
 8  rows  in  set ( 0.00   sec)

(dg7)root@localhost [mytest] >  show slave status\G
 ***************************  1 . row *************************** 
               Slave_IO_State: Waiting   for   master to send event
                  Master_Host:   192.168 . 80.106  
                  Master_User: repl
                  Master_Port:   3306  
                Connect_Retry:   60  
              Master_Log_File: dg6 -logbin. 000001  
          Read_Master_Log_Pos:   16026  
               Relay_Log_File: dg7 -relay-bin. 000005  
                Relay_Log_Pos:   8829  
        Relay_Master_Log_File: dg6 -logbin. 000001  
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql
           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:   16026  
              Relay_Log_Space:   9603  
              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: b888e1ea - 9739 -11e4-a24e- 000c29b24887
             Master_Info_File:  /data/mydata/master. info  
                    SQL_Delay:   0  
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting   for  the slave I/ O thread to update it
           Master_Retry_Count:   86400  
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: b888e1ea - 9739 -11e4-a24e-000c29b24887:查看更多关于MySQL复制应用中继日志解析的详细内容...

  阅读:24次