|NO.Z.00040|——————————|BigDataEnd|——|Java&MySQL单表/约束/事务.V18|——|MySQL.v18|不可复读演示及解决|
一、不可复读演示及解决
### --- 不可复读演示及解决
——> 将全局的隔离级别进行提升为:repeatable read
### --- 恢复数据
UPDATE account SET money = 1000
### --- 打开A窗口,设置隔离级别为:repeatabled read
-- 查看事务隔离级别
select @@tx_isolation;
-- 设置事务隔离级别为 repeatable read
set global transaction isolation level repeatable read;

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

### --- B窗口事务,先进行第一次查询
select * from account;

### --- A窗口更新数据,然后提交事务
-- 修改数据
update account set money = money + 500 where name = 'tom';
-- 提交事务
commit;
### --- B窗口,再次查询
——> 同一个事务中为了保证多次查询数据一致,必须使用 repeatable read 隔离级别
select * from account;

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
浙公网安备 33010602011771号