Mysql InnoDB下的两种行锁
今天例举2种常见的Mysql InnoDB下的行锁
现有表dr_test(id pk, name)
数据是
1 zhangsan
2 lisi
3 wangwu
例子1
事务1 update dr_test set name='zhaoliu' where id=1
事务2 update dr_test set name='zhaoliu1' where id=1
因为事务1对pk id =1的数据行加了行锁,事务2会阻塞
例子2
事务1 delete from dr_test where id=1
事务2 insert into dr_test(id,name) value (1,"zhaoliu");
因为事务1对pk id =1的数据行加了行锁,事务2会阻塞
Lock wait timeout exceeded; try restarting transaction