MySQL复制应用中继日志解析

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

SQL线程应用中继日志,在binlog_format是row格式的时候,是居于主键更新,下面结合一张图来证明

从一个大神那边得到一张图片,SQL线程应用中继日志流程,下面就实验验证一下:(PS,我个人认为这张图binlog_format为ROW格式是正确的)

 

 

 

2.验证有PK表情况

在主库创建表结构

CREATE TABLE `table_pk` (
`id`  int(11) NOT NULL ,
`name`  varchar(20) NOT NULL ,
`age`  tinyint NOT NULL ,
`sex`  tinyint NOT NULL COMMENT '0,man,1,woman' ,

PRIMARY KEY (`id`)
) ENGINE=InnoDB;

插入测试数据

insert into table_pk (`id`,`name`,`age`,`sex`) values(111,'zhangsan',20,0);
insert into table_pk (`id`,`name`,`age`,`sex`) values(222,'lisi',22,1);
insert into table_pk (`id`,`name`,`age`,`sex`) values(333,'wangwu',22,1);
insert into table_pk (`id`,`name`,`age`,`sex`) values(444,'lilei',32,0);
insert into table_pk (`id`,`name`,`age`,`sex`) values(555,'hanmeimei',30,1);

(dg6)root@localhost [(none)]> use mytest;

(dg6)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 |
+-----+-----------+-----+-----+
rows in set (0.00 sec)

(dg6)root@localhost [mytest]> show global variables like '%binlog_format%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW   |
+---------------+-------+
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 |
+-----+-----------+-----+-----+
rows in set (0.00 sec)

(dg7)root@localhost [mytest]> show global variables like '%binlog_format%';
+--------------------------+-------------------+
| Variable_name            | Value             |
+--------------------------+-------------------+
| binlog_format            | ROW               |
+--------------------------+-------------------+
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
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 |
+-----+-----------+-----+-----+
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 |
+-----+--------+-----+-----+
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 |
+-----+---------+-----+-----+
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 |
+-----+--------+-----+-----+
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 |
+-----+---------+-----+-----+
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 |
+-----+--------+-----+-----+
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
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 |
+-----+-----------+-----+-----+
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 |
+-----+-----------+-----+-----+
rows in set (0.00 sec)
我们在从库继续搞破坏,把name为lisi的age修改为33,这时候主从已经不一致了。
(dg7)root@localhost [mytest]> select * from table_index where name='lisi';
+-----+------+-----+-----+
| id  | name | age | sex |
+-----+------+-----+-----+
| 222 | lisi |  22 |   1 |
+-----+------+-----+-----+
row in set (0.00 sec)


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

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

(dg7)root@localhost [mytest]>
那么我们还是在主库更新一下记录。把lisi的age修改成30,看看从库能不能更新过来
(dg6)root@localhost [mytest]> select * from table_index where name='lisi';
+-----+------+-----+-----+
| id  | name | age | sex |
+-----+------+-----+-----+
| 222 | lisi |  22 |   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 |
+-----+------+-----+-----+
row in set (0.00 sec)

(dg6)root@localhost [mytest]>
回到从库看看,数据没有更新过来,lisi的年龄还是33,这时候主从复制也是异常的,提示1032错误(找不到记录)
(dg7)root@localhost [mytest]> select * from table_index where name='lisi';
+-----+------+-----+-----+
| id  | name | age | sex |
+-----+------+-----+-----+
| 222 | lisi |  33 |   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
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 |
+-----+-----+-----------+-----+-----+
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 |
+-----+-----+--------+-----+-----+
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 |
+-----+-----+--------+-----+-----+
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 |
+-----+-----+-----------+-----+-----+
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 |
+-----+-----+---------+-----+-----+
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
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 |
+-----+-----+--------+-----+-----+
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
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 |
+-----+-----------+-----+-----+
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 |
+-----+-----------+-----+-----+
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 |
+-----+-----------+-----+-----+
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 |
+----+-------------+-----------+-------+---------------+-----------+---------+-------+------+-------------+
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 |
+-----+-----------+-----+-----+
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 |
+-----+-----------+-----+-----+
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:1-63
            Executed_Gtid_Set: a9926b45-975d-11e4-a339-000c29b24888:1-28,
b888e1ea-9739-11e4-a24e-000c29b24887:1-63
                Auto_Position: 1
row in set (0.00 sec)

(dg7)root@localhost [mytest]>

6.验证只有普通索引情况

主库
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',
   key age_index (`age`)
  ) ENGINE=InnoDB 
(dg6)root@localhost [mytest]>select * from table_key where age=20;
+-----+----------+-----+-----+
| id  | name     | age | sex |
+-----+----------+-----+-----+
| 111 | zhangsir |  20 |   0 |
+-----+----------+-----+-----+
row in set (0.00 sec)

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

(dg6)root@localhost [mytest]>select * from table_key where age=20;
+-----+---------+-----+-----+
| id  | name    | age | sex |
+-----+---------+-----+-----+
| 111 | zhaoliu |  20 |   0 |
+-----+---------+-----+-----+
row in set (0.00 sec)
从库
(dg7)root@localhost [mytest]> select * from table_key where age=20;
+-----+----------+-----+-----+
| id  | name     | age | sex |
+-----+----------+-----+-----+
| 111 | zhangsir |  20 |   0 |
+-----+----------+-----+-----+
row in set (0.00 sec)

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

(dg7)root@localhost [mytest]> select * from table_key where age=20;
+-----+----------+-----+-----+
| id  | name     | age | sex |
+-----+----------+-----+-----+
| 111 | zhangsan |  20 |   0 |
+-----+----------+-----+-----+
row in set (0.00 sec)

(dg7)root@localhost [mytest]> select * from table_key where age=20;
+-----+----------+-----+-----+
| id  | name     | age | sex |
+-----+----------+-----+-----+
| 111 | zhangsan |  20 |   0 |
+-----+----------+-----+-----+
row in set (0.00 sec)
##########################提示1032错误,找不到记录

(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: 16463
               Relay_Log_File: dg7-relay-bin.000005
                Relay_Log_Pos: 8993
        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_key; Can't find record in 'table_key', Error_code: 1032; Column 'name' cannot be null, Error_code: 1048; Column 'age' cannot be null, Error_code: 1048; Column 'sex' cannot be null, Error_code: 1048; handler error HA_ERR_END_OF_FILE; the event's master log dg6-logbin.000001, end_log_pos 16432
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 16190
              Relay_Log_Space: 10040
              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_key; Can't find record in 'table_key', Error_code: 1032; Column 'name' cannot be null, Error_code: 1048; Column 'age' cannot be null, Error_code: 1048; Column 'sex' cannot be null, Error_code: 1048; handler error HA_ERR_END_OF_FILE; the event's master log dg6-logbin.000001, end_log_pos 16432
  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 09:43:27
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: b888e1ea-9739-11e4-a24e-000c29b24887:1-65
            Executed_Gtid_Set: a9926b45-975d-11e4-a339-000c29b24888:1-29,
b888e1ea-9739-11e4-a24e-000c29b24887:1-64
                Auto_Position: 1
row in set (0.00 sec)

(dg7)root@localhost [mytest]>

7.binlog格式是sbr,mbr格式的时候(PS,因为我使用了GTID,所以找了另外两台机测试)

主库

(dg1)root@127.0.0.1 [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 |
+-----+-----------+-----+-----+
rows in set (0.00 sec)

(dg1)root@127.0.0.1 [mytest]> show global variables like '%binlog_format%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | MIXED |
+---------------+-------+
row in set (0.00 sec)

(dg1)root@127.0.0.1 [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 |
+-----+-----------+-----+-----+
rows in set (0.00 sec)


(dg1)root@127.0.0.1 [mytest]> update table_key set name='zhangzong' where age=20;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
从库看一下
(dg2)root@127.0.0.1 [mytest]> select * from table_key where age=20;
+-----+----------+-----+-----+
| id  | name     | age | sex |
+-----+----------+-----+-----+
| 111 | zhangsan |  20 |   0 |
+-----+----------+-----+-----+
row in set (0.01 sec)

(dg2)root@127.0.0.1 [mytest]> update table_key set name='zhangsir' where age=20;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

(dg2)root@127.0.0.1 [mytest]> select * from table_key where age=20;
+-----+----------+-----+-----+
| id  | name     | age | sex |
+-----+----------+-----+-----+
| 111 | zhangsir |  20 |   0 |
+-----+----------+-----+-----+
row in set (0.00 sec)

(dg2)root@127.0.0.1 [mytest]> select * from table_key where age=20;
+-----+-----------+-----+-----+
| id  | name      | age | sex |
+-----+-----------+-----+-----+
| 111 | zhangzong |  20 |   0 |
+-----+-----------+-----+-----+
row in set (0.00 sec)

(dg2)root@127.0.0.1 [mytest]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.80.101
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: dg1.000001
          Read_Master_Log_Pos: 3340
               Relay_Log_File: mysql3307-relay-bin.000002
                Relay_Log_Pos: 3355
        Relay_Master_Log_File: dg1.000001
             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: 3340
              Relay_Log_Space: 3532
              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: 12
                  Master_UUID: fbc1bdf1-829b-11e4-9bdf-000c29b24882
             Master_Info_File: /data/3307/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: 
            Executed_Gtid_Set: 
                Auto_Position: 0
row in set (0.00 sec)


(dg2)root@127.0.0.1


本文来自云栖社区合作伙伴“DBGEEK”


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4天前
|
存储 SQL 监控
|
6天前
|
机器学习/深度学习 人工智能 自然语言处理
思通数科AI平台在尽职调查中的技术解析与应用
思通数科AI多模态能力平台结合OCR、NLP和深度学习技术,为IPO尽职调查、融资等重要交易环节提供智能化解决方案。平台自动识别、提取并分类海量文档,实现高效数据核验与合规性检查,显著提升审查速度和精准度,同时保障敏感信息管理和数据安全。
40 11
|
4天前
|
自然语言处理 监控 数据可视化
|
2天前
|
自然语言处理 并行计算 数据可视化
免费开源法律文档比对工具:技术解析与应用
这款免费开源的法律文档比对工具,利用先进的文本分析和自然语言处理技术,实现高效、精准的文档比对。核心功能包括文本差异检测、多格式支持、语义分析、批量处理及用户友好的可视化界面,广泛适用于法律行业的各类场景。
|
5天前
|
安全 编译器 PHP
PHP 8新特性解析与实践应用####
————探索PHP 8的创新功能及其在现代Web开发中的实际应用
|
6天前
|
机器学习/深度学习 人工智能 自然语言处理
医疗行业的语音识别技术解析:AI多模态能力平台的应用与架构
AI多模态能力平台通过语音识别技术,实现实时转录医患对话,自动生成结构化数据,提高医疗效率。平台具备强大的环境降噪、语音分离及自然语言处理能力,支持与医院系统无缝集成,广泛应用于门诊记录、多学科会诊和急诊场景,显著提升工作效率和数据准确性。
|
8天前
|
机器学习/深度学习 人工智能 安全
TPAMI:安全强化学习方法、理论与应用综述,慕工大、同济、伯克利等深度解析
【10月更文挑战第27天】强化学习(RL)在实际应用中展现出巨大潜力,但其安全性问题日益凸显。为此,安全强化学习(SRL)应运而生。近日,来自慕尼黑工业大学、同济大学和加州大学伯克利分校的研究人员在《IEEE模式分析与机器智能汇刊》上发表了一篇综述论文,系统介绍了SRL的方法、理论和应用。SRL主要面临安全性定义模糊、探索与利用平衡以及鲁棒性与可靠性等挑战。研究人员提出了基于约束、基于风险和基于监督学习等多种方法来应对这些挑战。
20 2
|
3天前
|
前端开发 中间件 PHP
PHP框架深度解析:Laravel的魔力与实战应用####
【10月更文挑战第31天】 本文作为一篇技术深度好文,旨在揭开PHP领域璀璨明星——Laravel框架的神秘面纱。不同于常规摘要的概括性介绍,本文将直接以一段引人入胜的技术剖析开场,随后通过具体代码示例和实战案例,逐步引导读者领略Laravel在简化开发流程、提升代码质量及促进团队协作方面的卓越能力。无论你是PHP初学者渴望深入了解现代开发范式,还是经验丰富的开发者寻求优化项目架构的灵感,本文都将为你提供宝贵的见解与实践指导。 ####
|
6天前
|
前端开发 JavaScript
JavaScript新纪元:ES6+特性深度解析与实战应用
【10月更文挑战第29天】本文深入解析ES6+的核心特性,包括箭头函数、模板字符串、解构赋值、Promise、模块化和类等,结合实战应用,展示如何利用这些新特性编写更加高效和优雅的代码。
18 0
|
10天前
|
存储 人工智能 大数据
拼多多详情API的价值与应用解析
拼多多作为中国电商市场的重要参与者,其开放平台提供的商品详情API接口为电商行业带来了新的机遇和挑战。该接口允许开发者通过编程方式获取商品的详细信息,包括标题、价格、描述、图片、规格参数和库存等,推动了电商运营的智能化和高效化。本文将深入解析拼多多详情API的价值与应用,帮助商家和开发者更好地理解和利用这一宝贵资源。
20 0

推荐镜像

更多
下一篇
无影云桌面