mysql 行锁一则
CREATE TABLE `t1` (
`id` int(11) NOT NULL DEFAULT '0',
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
`id` int(11) NOT NULL DEFAULT '0',
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
transaction 1
mysql> select * from t1 where id=1 for update;
+----+---------+
| id | name |
+----+---------+
| 1 | Chinese |
+----+---------+
1 row in set (0.00 sec)
transaction 2
mysql> select * from t1 where id=2 for update;
+----+---------+
| id | name |
+----+---------+
| 2 | Chinese |
+----+---------+
1 row in set (0.00 sec)
transaction 3
mysql> select * from t1 where id in (3,1) for update;
waiting……
transaction 4
mysql> select * from t1 where id=3 for update;
+----+------+
| id | name |
+----+------+
| 3 | hu |
+----+------+
1 row in set (0.00 sec)
结论:id=3的行并没有被事物3锁住。 处在锁等待中的事物并不会对行进行加锁。