mysql> use world;
mysql> show tables;
+-----------------+
| Tables_in_world |
+-----------------+
| city |
| country |
| countrylanguage |
+-----------------+
3 rows in set (0.00 sec)
s1:
# 加排他锁
mysql> begin;
mysql> select * from world.city where id=1 for update;
s2:
# 加排他锁
mysql> begin;
mysql> update city set name='girl' where id=1;
执行完处于夯住状态,默认50秒会超时回滚。
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> set innodb_lock_wait_timeout=5000; ##锁等待超时参数,这里设置为5000便于测试.
mysql> update city set name='girl' where id=1;