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)

  • 相关阅读:
    RabbitMq使用说明
    php使用rabbitmq需安装amqp拓展协议
    新建springboot web项目pom报错
    HttpRunner Manager 接口自动化平台搭建
    数据库存储过程进行批量插入数据
    Windows系统下Robot Framework的安装
    利用Charles模拟客户端弱网环境进行弱网测试
    JMeter进行简单的接口压测
    JMeter的安装和使用
    grep, sed 和 awk 学习总结
  • 原文地址:https://www.cnblogs.com/yhq1314/p/10043143.html
Copyright © 2011-2022 走看看