1、实验环境
Myql版本5.7.17-log
实验表结构
(root@localhost)[apex]> show create table test;
+-------+-----------------------------------------------------------------------------------------------------------------------------------+
| Table| Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------+
|test | CREATE TABLE `test` (
`x` int(11) NOT NULL,
`y` int(11) DEFAULT NULL,
PRIMARY KEY (`x`)
)ENGINE=InnoDB DEFAULT CHARSET=gbk |
+-------+-----------------------------------------------------------------------------------------------------------------------------------+
1 row inset (0.01 sec)
插入数据
(root@localhost)[apex]> insert into test values(1,1);
(root@localhost)[apex]> insert into test values(2,2);
(root@localhost)[apex]> insert into test values(3,3);
2、锁产生步骤
会话一:开启事务,更新数据,不提交
(root@localhost)[apex]> begin;
QueryOK, 0 rows affected (0.00 sec)
(root@localhost)[apex]> update test set y=y+1 where x=1;
QueryOK, 1 row affected (0.00 sec)
Rowsmatched: 1 Changed: 1 Warnings: 0
查看当前连接id号(线程id号)