zoukankan      html  css  js  c++  java
  • MySQL RR隔离 读一致性

    MySQL RR 模式下 事务隔离问题:
    
    Session 1:
    mysql> select * from test;
    +------+------+
    | id   | name |
    +------+------+
    | NULL | a    |
    |    2 | b    |
    |    3 | c    |
    |    1 | a01  |
    |    4 | a    |
    |    4 | a    |
    |    5 | c    |
    +------+------+
    7 rows in set (0.00 sec)
    
    mysql> update test set name='a999' where id=1;
    Query OK, 1 row affected (0.01 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> select * from test;
    +------+------+
    | id   | name |
    +------+------+
    | NULL | a    |
    |    2 | b    |
    |    3 | c    |
    |    1 | a999 |
    |    4 | a    |
    |    4 | a    |
    |    5 | c    |
    +------+------+
    7 rows in set (0.00 sec)
    
    
    Session 2:
    mysql>  select * from test ;
    +------+------+
    | id   | name |
    +------+------+
    | NULL | a    |
    |    2 | b    |
    |    3 | c    |
    |    1 | a01  |
    |    4 | a    |
    |    4 | a    |
    |    5 | c    |
    +------+------+
    7 rows in set (0.00 sec)
    
    mysql>  select * from test ;
    +------+------+
    | id   | name |
    +------+------+
    | NULL | a    |
    |    2 | b    |
    |    3 | c    |
    |    1 | a999 |
    |    4 | a    |
    |    4 | a    |
    |    5 | c    |
    +------+------+
    7 rows in set (0.00 sec)
    
    
    此时没有开启事务,RR模式下 更新立即被看到
    
    
    
    /****************************************************
    
    Session 2开启事务:
    
    
    
    SESSION 1:
    mysql> update test set name='a0101' where id=1;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> select * from test;
    +------+-------+
    | id   | name  |
    +------+-------+
    | NULL | a     |
    |    2 | b     |
    |    3 | c     |
    |    1 | a0101 |
    |    4 | a     |
    |    4 | a     |
    |    5 | c     |
    +------+-------+
    7 rows in set (0.00 sec)
    
    
    此时在查看Session 2:
    
    mysql>  select * from test ;
    +------+------+
    | id   | name |
    +------+------+
    | NULL | a    |
    |    2 | b    |
    |    3 | c    |
    |    1 | a999 |
    |    4 | a    |
    |    4 | a    |
    |    5 | c    |
    +------+------+
    7 rows in set (0.00 sec)
    
    mysql> commit;
    Query OK, 0 rows affected (0.00 sec)  ---需要手动提交事务
    
    mysql>  select * from test ;
    +------+-------+
    | id   | name  |
    +------+-------+
    | NULL | a     |
    |    2 | b     |
    |    3 | c     |
    |    1 | a0101 |
    |    4 | a     |
    |    4 | a     |
    |    5 | c     |
    +------+-------+
    7 rows in set (0.00 sec)

  • 相关阅读:
    jquery 实现可编辑div
    【ubuntu firefox】 Firefox is already running, but is not responding
    PO标准form的一点疑问
    hdu3488Tour KM算法
    经典算法学习——归并排序
    Linux 安装Redis全过程日志
    算法竞赛入门经典 习题 2-10 排列(permutation)
    每日一支TED——弗兰斯·兰庭:为动物发声的摄影作品——2015年6月3日
    Linux用户密码策略
    chage命令
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350376.html
Copyright © 2011-2022 走看看