mysql事务及锁使用测试
mysql -h127.0.0.1 -P3306 -uroot -p123456
use test;
select * from testtb;
start transaction;
commit;
并发事务处理带来的问题:
更新丢失:两个或多个事务选择同一行,然后基于最初选定的值更新该行,每个事务都不知道其他事务的存在。
单靠数据库事务控制器无法解决

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

网友评论