我用的是MySQL 5.5.28
CREATE TABLE `t` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
# 会话A
mysql> select * from t;
+---+
| a |
+---+
| 1 |
| 2 |
| 4 |
+---+
3 rows in set (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.05 sec)
mysql> select * from t where a < 4 for update;
+---+
| a |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.12 sec)
# 会话B
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t select 5;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
默认的是REPEATABLE-READ, 为什么insert id =5 会被block呢?按理说使用的Next-key Lock,a<4锁定的区间应该是(无穷小, 4],求指教。 |
|