• mysql如果存在一行数据,主库和从库主键相同而其他列值不同,源端Update或者delete该行,从库会update和delete这一行吗


    从库会update或delete,而且会update成和主库完全相同的一行。这一点主从复制和CDC复制的一样的,都是以主键为查询基准的。复制程序很聪明,如果一张表存在主键的话,update或着delete该表的话,从库的复制程序会通过主键索引查询改行,如果主键返回一行数据就默认是完全相同一行的数据,而不会再去对比其他列值。

    update测试:

    主库:

    mysql> create table test_strict (id int not null primary key,name varchar(10));
    Query OK, 0 rows affected (0.02 sec)


    mysql> insert into test_strict values(1,'lisi'); 
    Query OK, 1 row affected (0.00 sec)

    mysql> select * from test_strict;
    +----+------+
    | id | name |
    +----+------+
    |  1 | lisi |
    +----+------+
    1 row in set (0.00 sec)

    从库:

    [root@localhost:mytest1]>select * from test_strict;
    +----+------------+
    | id | name       |
    +----+------------+
    |  1 | zhangsan88 |
    +----+------------+
    1 row in set (0.00 sec)

    主库:

    mysql> update test_strict set id=88 where id=1 and name='lisi';
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0

    mysql> 

    从库:

    [root@localhost:mytest1]>select * from test_strict;
    +----+------+
    | id | name |
    +----+------+
    | 88 | lisi |
    +----+------+
    1 row in set (0.00 sec)

    delete测试:

    主:

    mysql> select * from test_strict;
    +----+------+
    | id | name |
    +----+------+
    | 88 | lisi |
    +----+------+
    1 row in set (0.00 sec)
    从:

    [root@localhost:mytest1]>select * from test_strict;
    +----+-----------+
    | id | name      |
    +----+-----------+
    | 88 | zhangsan3 |
    +----+-----------+
    1 row in set (0.00 sec)

    主:

    mysql> delete from test_strict where id=88 and name='lisi';
    Query OK, 1 row affected (0.00 sec)

    从:

    [root@localhost:mytest1]>select * from test_strict;
    Empty set (0.00 sec)

  • 相关阅读:
    使用策略模式优化多重if/else
    【NOWCODER】- Python:列表(二)
    基于flask写一个接口
    会计论文选题什么方面比较好写且重复率较低?
    从CentOS6升级到CentOS7要注意的一些事项
    入门力扣自学笔记77 C++ (题目编号535)
    内存==c语言1
    ubuntu 查询流量使用
    C++11新特性(智能指针详细介绍)
    基于pythonGUI的图形绘图及图元编辑系统
  • 原文地址:https://blog.csdn.net/liys0811/article/details/133077041