美文网首页
mysql for update

mysql for update

作者: fuchai2371 | 来源:发表于2018-12-31 12:59 被阅读0次

在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

相关文章

网友评论

      本文标题:mysql for update

      本文链接:https://www.haomeiwen.com/subject/rwbilqtx.html