MySQL: 解决不可重复读问题

  • 将全局的隔离级别进行提升为: repeatable read

1. 恢复数据

UPDATE account SET money = 1000

2. 打开A 窗口, 设置隔离级别为:repeatable read

-- 查看事务隔离级别 
select @@tx_isolation;

-- 设置事务隔离级别为 
repeatable read set global transaction isolation level repeatable read;

3. 重新开启 A,B 窗口 选择数据库 ,同时开启事务

 

4. B 窗口事务 先进行第一次查询

 select * from account;

 

 

5. A 窗口更新数据, 然后提交事务

 -- 修改数据 
update account set money = money + 500 where name = 'tom';
 -- 提交事务 
commit;
 

6. B 窗口 再次查询

select * from account;

 

 

同一个事务中为了保证多次查询数据一致,必须使用 repeatable read 隔离级别

posted @ 2021-07-15 09:53  Jasper2003  阅读(391)  评论(0编辑  收藏  举报