zoukankan      html  css  js  c++  java
  • my42_Mysql基于ROW格式的主从同步

    模拟主从update事务,从库跳过部分update事务后,再次开始同步的现象

    主库

    mysql> select * from dbamngdb.isNodeOK;
    +----+---------------------+-------+
    | id | update_time         | count |
    +----+---------------------+-------+
    |  1 | 2019-11-08 18:51:48 |     1 |
    +----+---------------------+-------+
    1 row in set (0.00 sec)
    
    mysql> update dbamngdb.isNodeOK set count = count + 100;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    

     从库

    将从库的数据重置,相当于丢失了一部分事务

    mysql>  update dbamngdb.isNodeOK set count = 1;
    Query OK, 1 row affected (0.03 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    mysql> select * from isnodeok; +----+---------------------+-------+ | id | update_time | count | +----+---------------------+-------+ | 1 | 2019-11-08 18:51:48 | 1 | +----+---------------------+-------+ 1 row in set (0.03 sec)

    主库

    mysql> update dbamngdb.isNodeOK set count = count + 100;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> select * from dbamngdb.isNodeOK;
    +----+---------------------+-------+
    | id | update_time         | count |
    +----+---------------------+-------+
    |  1 | 2019-11-08 18:51:48 |   201 |
    +----+---------------------+-------+
    1 row in set (0.00 sec)
    

    从库

    mysql> select * from isnodeok;
    +----+---------------------+-------+
    | id | update_time         | count |
    +----+---------------------+-------+
    |  1 | 2019-11-08 18:51:48 |   201 |
    +----+---------------------+-------+
    1 row in set (0.03 sec)
    

    当主库再次update时,从库的数据就跟主库一致了,这是因为ROW格式下,从库的update是全行更新,不管主库更新的有多少个字段。

    关于所有列皆更新,实验如下:

    从库修改字段

    mysql> update dbamngdb.isNodeOK set update_time=now();
    Query OK, 1 row affected (0.03 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> select * from isnodeok;
    +----+---------------------+-------+
    | id | update_time         | count |
    +----+---------------------+-------+
    |  1 | 2019-11-08 19:05:18 |   201 |
    +----+---------------------+-------+
    1 row in set (0.02 sec)
    

    主库修改另外的字段

    mysql> select * from dbamngdb.isNodeOK;
    +----+---------------------+-------+
    | id | update_time         | count |
    +----+---------------------+-------+
    |  1 | 2019-11-08 18:51:48 |   201 |
    +----+---------------------+-------+
    1 row in set (0.00 sec)
    
    mysql> update dbamngdb.isNodeOK set count = count + 100;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> select * from dbamngdb.isNodeOK;
    +----+---------------------+-------+
    | id | update_time         | count |
    +----+---------------------+-------+
    |  1 | 2019-11-08 18:51:48 |   301 |
    +----+---------------------+-------+
    1 row in set (0.00 sec)
    

     再次查看从库,我们预期从库的update_time字段值变化为主库的字段值

    mysql> select * from isnodeok;
    +----+---------------------+-------+
    | id | update_time         | count |
    +----+---------------------+-------+
    |  1 | 2019-11-08 18:51:48 |   301 |
    +----+---------------------+-------+
    1 row in set (0.03 sec)
    

     结果与预期一致,这就是ROW格式更新,不管主库更新了几个字段,从库都是全行更新。并且主键号与主库保持一致。

  • 相关阅读:
    团队项目-smart原则
    团队项目-作业管理系统
    团队模式和团队的开发模式是什么,它们有什么关系?
    软件工作量的估计有哪些方法?
    腾讯qq的发展史
    软件过程与项目管理(第二次作业)
    有学生提到,在大学选课的时候,可以写一个“刷课机”的程序,利用学校选课系统的弱点或漏洞,帮助某些人选到某些课程。或者帮助用户刷购票网站,先买到火车票。这些软件合法么?符合道德规范么?是在“软件工程”的研究范围么?
    mysql中explain的type的解释
    php 中类型转换 numfamat、round函数tips
    python client端收不到server端构造的结构体数据
  • 原文地址:https://www.cnblogs.com/perfei/p/11822745.html
Copyright © 2011-2022 走看看