怎么理解mysql innodb的行锁
基于索引上锁,而不是针对选出来的具体的行
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