ITPub博客

首页 > 数据库 > MySQL > innodb行锁

innodb行锁

原创 MySQL 作者:fei890910 时间:2016-05-29 19:15:25 0 删除 编辑
三种级别
record lock  锁住某一行记录  
gap lock     锁住某一段范围中的记录 
next key lock 是前两者效果的叠加

实验环境
mysql> select @@tx_isolation;
+-----------------+
| @@tx_isolation  |
+-----------------+
| REPEATABLE-READ |
+-----------------+
1 row in set (0.00 sec)
mysql> select * from t;
+------+
| id   |
+------+
|    2 |
|    8 |
|   19 |
|   22 |
+------+
mysql> create index t_ind on t(id);
Query OK, 0 rows affected (8.52 sec)
 同时打开两个会话,并打开事物
会话一
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from t where id=19;
Query OK, 1 row affected (0.00 sec)
会话二
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t values(55);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t values(10);
^C^C -- query aborted
ERROR 1317 (70100): Query execution was interrupted
mysql> 
mysql> insert into t values(1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t values(12);
^C^C -- query aborted
ERROR 1317 (70100): Query execution was interrupted
mysql> 
会话二说明8-22之间被锁住了,无法插入数据.这就是gap lock          
                                             
取消gap lock
修改事物的隔离级别到READ COMMITTED                             

                                                     

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29108064/viewspace-2108867/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: pg_basebackup的使用
请登录后发表评论 登录
全部评论

注册时间:2013-08-15

  • 博文量
    122
  • 访问量
    811205