mysql update 等值 锁区间
来源:互联网 发布:aws s3 上传文件 php 编辑:程序博客网 时间:2024/05/21 13:57
CREATE TABLE `p300` ( `sn` int(11) NOT NULL AUTO_INCREMENT, `uuid` int(11) NOT NULL, `mobilePhone` int(11) NOT NULL, PRIMARY KEY (`sn`), KEY `p100_idx1` (`uuid`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mysql> insert into p300 select sn,sn,mobilePhone from p300;Query OK, 17736 rows affected (0.20 sec)Records: 17736 Duplicates: 0 Warnings: 0Session 1:mysql> select connection_id(); +-----------------+| connection_id() |+-----------------+| 1 |+-----------------+1 row in set (0.00 sec)mysql> select * from p300 where sn<20;+----+------+-------------+| sn | uuid | mobilePhone |+----+------+-------------+| 1 | 1 | 111 || 3 | 3 | 3333 || 5 | 5 | 5555 || 10 | 10 | 222 |+----+------+-------------+4 rows in set (0.00 sec)mysql> start transaction;Query OK, 0 rows affected (0.00 sec)mysql> select * from p300 where uuid = 6 for update;Empty set (0.00 sec)Session 2:mysql> select connection_id();+-----------------+| connection_id() |+-----------------+| 2 |+-----------------+1 row in set (0.00 sec)mysql> start transaction;Query OK, 0 rows affected (0.00 sec)mysql> start transaction;Query OK, 0 rows affected (0.00 sec)mysql> insert into p300 values(1,1,1);ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'mysql> insert into p300(uuid,mobilePhone) values(1,1);Query OK, 1 row affected (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(2,1);Query OK, 1 row affected (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(3,1);Query OK, 1 row affected (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(4,1);Query OK, 1 row affected (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(5,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(6,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(7,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(8,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(9,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(10,1);Query OK, 1 row affected (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(11,1);Query OK, 1 row affected (0.00 sec)虽然select * from p300 where uuid = 6 for update; uud=6并不存在,但是还是锁了[5,10)那么有值的情况 mysql 是怎么锁区间的呢?Session 1:mysql> select connection_id(); +-----------------+| connection_id() |+-----------------+| 1 |+-----------------+1 row in set (0.00 sec)mysql> select * from p300 where sn<20;+----+------+-------------+| sn | uuid | mobilePhone |+----+------+-------------+| 1 | 1 | 111 || 3 | 3 | 3333 || 5 | 5 | 5555 || 10 | 10 | 222 |+----+------+-------------+4 rows in set (0.00 sec)mysql> start transaction;Query OK, 0 rows affected (0.00 sec)mysql> select * from p300 where uuid =5 for update;+----+------+-------------+| sn | uuid | mobilePhone |+----+------+-------------+| 5 | 5 | 5555 |+----+------+-------------+1 row in set (0.00 sec)Session 2:mysql> select connection_id(); +-----------------+| connection_id() |+-----------------+| 2 |+-----------------+1 row in set (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(1,1);Query OK, 1 row affected (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(2,1);Query OK, 1 row affected (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(3,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(3,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(4,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(5,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(6,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(7,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(8,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(9,1);ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionmysql> insert into p300(uuid,mobilePhone) values(10,1);Query OK, 1 row affected (0.00 sec)mysql> insert into p300(uuid,mobilePhone) values(11,1);Query OK, 1 row affected (0.00 sec)select * from p300 where uuid =5 for update; 有值 此时锁住的区间是[5,10);
0 0
- mysql update 等值 锁区间
- mysql锁-for update
- mysql 区间锁
- mysql 数据库 for update 锁
- MySQL左连接/右连接/等值连接
- Mysql中float列的等值查询
- MySQL左连接,右连接,等值连接
- MySQL左连接、右连接、等值连接
- mysql update
- MYSQL UPDATE
- update mysql
- mysql update
- mysql update
- mysql -update
- Mysql update 子查询锁表问题。
- Mysql update 子查询锁表问题。
- mysql select ....for update排他锁
- MySQL更新锁(for update)摘要
- 深入剖析Java中的装箱和拆箱
- VS界面绘制双缓存
- Linux学习总结(22)——CentOS7.2安装Nginx
- Eclipse 集成ijkplayer demo
- amber中非标准氨基酸残基的参数生成
- mysql update 等值 锁区间
- HTTP状态码大全
- listview回到顶部
- 几个闭包的案例
- C语言基础(六)- 结构体、共用体、枚举和typeof自定义类型
- Android组件之Activity解析
- strip去符号
- 动态代理的一个demo
- 高通使用/system/bin/r读取msm8916的gpio配置