数据库
首页 > 数据库> > MySQL: 解决不可重复读问题

MySQL: 解决不可重复读问题

作者:互联网

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 隔离级别

标签:事务,隔离,重复,不可,account,read,repeatable,MySQL,--
来源: https://www.cnblogs.com/JasperZhao/p/15014041.html