1、脏读
![](https://img-blog.csdn.net/201802211302470)
1.1避免脏读现象
#避免脏读
#开启事务A
start transaction;
#关闭自动提交
set @@autocommit = 0
show variables like '%autocommit%'
update student set name = 'kangkang232' where id =1;
select * from student where id =1
rollback;
commit;
#开启事务B
start transaction;
#设置隔离级别为读已提交
set session transaction isolation level read committed;
select * from student where id =1
commit;
2、不可重复读
![](https://img-blog.csdn.net/20180221131858679)
#避免重复读
#事务A
commit;
start transaction;
update student set name = 'cc' where id = 1;
commit;
#事务B
commit;
set session transaction isolation level repeatable read;
start transaction;
select * from student where id = 1;
3、幻读
![](https://img-blog.csdn.net/20180221132448826)
#避免幻读
#事务A
commit;
set session transaction isolation level serializable;
start transaction;
select * from student where id =1;
select * from student where id =1;
#事务B
commit;
start transaction;
insert into student values(12345,'mdm',110);
commit
欢迎关注我的公众号:小秋的博客
CSDN博客:https://blog.csdn.net/xiaoqiu_cr
github:https://github.com/crr121
联系邮箱:rongchen633@gmail.com
有什么问题可以给我留言噢~