美文网首页
mysql事务及锁使用测试

mysql事务及锁使用测试

作者: kaizhi | 来源:发表于2019-02-27 16:32 被阅读2次

    mysql事务及锁使用测试
    mysql -h127.0.0.1 -P3306 -uroot -p123456
    use test;
    select * from testtb;
    start transaction;
    commit;

    并发事务处理带来的问题:
    更新丢失:两个或多个事务选择同一行,然后基于最初选定的值更新该行,每个事务都不知道其他事务的存在。
    单靠数据库事务控制器无法解决


    image.png

    使用排他锁(X):
    select * from testtb where id=1 for update;


    image.png

    相关文章

      网友评论

          本文标题:mysql事务及锁使用测试

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