在mysql设计一个张表event,引擎是innodb,开启2个控制台,按照 t1 t2 t3 t4 t5 t6 顺序执行
id num
1 18
开启控制台1
begin;
select num from event where id=1; //t1
select num from event where id=1; //t4
select num from event where id=1; //t6
开启控制台2
begin;
update event set num=20 where id=1 //t2
select num from event where id=1; //t3
commit //t5
【可重复读】结果:18 20 20 18
【不可重复读】结果:18 20 20 18
观察得出结论:
【可重复读】(mysql默认隔离级别)
事务开始后不被其它【已提交】【未提交】的SQL 影响
单个事务中,修改值影响后面操作
【不可重复读】
事务开始后不被【未提交】的SQL影响,会被【已提交】的SQL影响
单个事务中,修改值影响后面操作
【补充】
mysql查看当前的隔离级别
show variables like 'transaction_isolation';
mysql设置隔离级别
set session/global transaction isolation level read uncommitted | read committed | repeatable read | serializable ;