基于索引上锁,而不是针对选出来的具体的行
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)
第一个会话
root@sakila 10:18:39>select * from tab_no_index where id=1 and name='1' for update;
+------+------+
| id | name |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.00 sec)
第二个会话
root@sakila 10:18:42>select * from tab_no_index where id=1 and name='4' for update;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
即使是想更新不同的一条记录,也需要等第一个会话释放锁。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/674865/viewspace-2135285/
,如需转载,请注明出处,否则将追究法律责任。