zoukankan      html  css  js  c++  java
  • MySQL 更新失效

    create table t(id int not null PRIMARY key,c int default null) engine=innodb;
    insert into t(id,c)values(1,1),(2,2),(3,3),(4,4);

    session1                                    session2
    (system@127.0.0.1:3306) [test]> show variables like '%iso%';
    +---------------+-----------------+
    | Variable_name | Value |
    +---------------+-----------------+
    | tx_isolation | REPEATABLE-READ |
    +---------------+-----------------+

    (system@127.0.0.1:3306) [test]> show variables like 'auto%';
    +--------------------------+-------+
    | Variable_name | Value |
    +--------------------------+-------+
    | auto_increment_increment | 1 |
    | auto_increment_offset | 1 |
    | autocommit | ON |
    | automatic_sp_privileges | ON |
    +--------------------------+-------+

    (system@127.0.0.1:3306) [test]> begin;
    Query OK, 0 rows affected (0.00 sec)
    (system@127.0.0.1:3306) [test]> select * from t;
    +----+------+
    | id | c |
    +----+------+
    | 1 | 1 |
    | 2 | 2 |
    | 3 | 3 |
    | 4 | 4 |
    +----+------+
    4 rows in set (0.00 sec)
                                          session2: (system@127.0.0.1:3306) [test]> update t set c=id+1;
    (system@127.0.0.1:3306) [test]> update t set c=0 where id=c;
    Query OK, 0 rows affected (4.39 sec)
    Rows matched: 0 Changed: 0 Warnings: 0
    //session1更新失效,update是当前读,此时已经找不到id=c的值,所以更新失败
    //rc情况,update还是会更新失效,跟隔离级别无关,都是当前读,只不过rc情况,下面的select就能读到session2的正确的值
    (system@127.0.0.1:3306) [test]> select * from t;
    +----+------+
    | id | c |
    +----+------+
    | 1 | 1 |
    | 2 | 2 |
    | 3 | 3 |
    | 4 | 4 |
    +----+------+
    4 rows in set (0.00 sec)
    (system@127.0.0.1:3306) [test]> commit;
    Query OK, 0 rows affected (0.00 sec)

    (system@127.0.0.1:3306) [test]> select * from t;
    +----+------+
    | id | c |
    +----+------+
    | 1 | 2 |
    | 2 | 3 |
    | 3 | 4 |
    | 4 | 5 |
    +----+------+
    4 rows in set (0.00 sec)

  • 相关阅读:
    MFC中处理消息的几个函数之间的区别
    双缓冲技术2
    CxImage简单用法2
    C/C++中 const,extern,static,volatile的使用(转帖)
    用BoundsChecker检测内存泄露2
    用BoundsChecker检测内存泄漏
    TrackMouseEvent函数实现鼠标停留响应
    3D——VTK使用
    防止密码被非法获取
    未来界面设计的主流——WPF技术
  • 原文地址:https://www.cnblogs.com/yhq1314/p/10043143.html
Copyright © 2011-2022 走看看