在mysql 数据库 修改数据库的时候经常会使用 for update 作为行级排它锁
例如:start transaction ; 自动commit 区别:set autocommit=0, 需要手动commit
select * from *** where id =1 for update ;
update *** set count = 100 where id= 1;
因为id为主键,所以仅锁住id=1的行,其他事务可以操作其他行数据
mysql8.0 引入了: UPDATE SKIP LOCKED; 跳过枷锁的行
FOR UPDATE NOWAIT; 枷锁失败不等待
具体参考:
https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html
网友评论