我正在使用两个窗口,因为我想实现事务的概念。
Window1:begin;
Window1:update employee set salary = 45000 where ssn = '123456789';
Window2:begin;
Window2:select * from employee where ssn = '123456789';
在这里,这个命令向我展示了之前正确的数据。
Window1:commit;
Window2:select * from employee where ssn = '123456789';
在这里,我应该得到45000的最新工资。但是我的窗口2只显示了之前的数据。我在哪里做错了?
发布于 2016-04-18 14:33:06
你的期望是错误的,仅此而已。事务从彼此的工作中看到什么是由所谓的transaction isolation levels决定的。mysql默认使用repeatable read isolation level,即:
如果事务隔离级别是可重复读取(默认级别),则同一事务中的所有一致读取都将读取该事务中第一个此类读取所建立的快照。
您可以将隔离级别更改为read committed,以启用您期望的行为:
具有READ COMMITTED隔离级别的
,事务内的每个一致读取都设置并读取其自己的最新快照。
https://stackoverflow.com/questions/36686695
复制相似问题