首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

MySQL的SELECT …for update

数据库表t_goods,包括id,status,name三个字段,id为主键,数据库中记录如下;   注:为了测试数据库锁,我使用两个console来模拟不同的事务操作,分别用console1、console2...lock)   console1:查询出结果,但是把该条数据锁定了 set autocommit=0; SELECT * from t_goods where id=1 for update;   console2...:查询被阻塞 console2:如果console1长时间未提交,则会报错 例2: (明确指定主键,若查无此数据,无lock)   console1:查询结果为空 set autocommit=0;...SELECT * from t_goods where id=4 for update;   console2:查询结果为空,查询无阻塞,说明console1没有对数据执行锁定 set autocommit...(无主键,table lock)   console1: set autocommit=0; SELECT * from t_goods where status=1 for update;   console2

3.7K30

悲观锁&乐观锁

+----+--------+------+   2 rows in set   mysql>   注:为了测试数据库锁,我使用两个console来模拟不同的事务操作,分别用console1、console2...   +----+--------+------+   |  1 |      1 | 道具 |   +----+--------+------+   1 row in set   mysql>   console2...:查询被阻塞 Sql代码   mysql> select * from t_goods where id=1 for update;   console2:如果console1长时间未提交,则会报错 Sql...name=装备 的数据,查询阻塞,说明console1把表给锁住了 Sql代码   mysql> select * from t_goods where name='装备' for update;   console2...:console1事务提交后,console2查询结果正常 Sql代码   mysql> select * from t_goods where id2 for update;   +----+--

98251

扫码

添加站长 进交流群

领取专属 10元无门槛券

手把手带您无忧上云

扫码加入开发者社群

相关资讯

热门标签

活动推荐

    运营活动

    活动名称
    广告关闭
    领券