隔离基本-- REPEATABLE-READ
root@sakila 10:14:32>show index from tab_no_index \G
*************************** 1. row ***************************
Table: tab_no_index
Non_unique: 1
Key_name: id
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 5
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
1 row in set (0.00 sec)
同一个会话:
set autocommit=0;
--在索引上使用了锁,具体使用哪个索引,需要看执行计划
root@sakila 10:11:17>select * from tab_no_index where id=1 for update;
+------+------+
| id | name |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.00 sec)
--即使同一个会话,插入一条相同key的记录也会锁住
root@sakila 10:11:32>insert into tab_no_index values(1,'4');
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
root@sakila 10:12:45>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/674865/viewspace-2135284/
,如需转载,请注明出处,否则将追究法律责任。