一 作用
1.1 结论
在mysql中,select ... for update 仅适用于InnoDB,且必须在事务块中才能生效。Innodb引擎默认是行锁。
Select .... from where .... for update 如果在where的查询条件字段使用了【主键|索引】,则此命令上行锁。否则,则命令上表锁。它是悲观锁的一种实现方式。
1.2 操作案例
1.2.1 查询条件为主键
场景1:查询条件为主键
会话A: select * from tb_pab where id=1 for update;
会话B: update tb_pab set uname='bj' where id=1;<

最低0.47元/天 解锁文章
3982

被折叠的 条评论
为什么被折叠?



