当前位置:网站首页>数据库隔离级别
数据库隔离级别
2022-07-06 06:08:00 【雪峰.贵】
根据并发情况引起的问题,修改隔离级别来避免。
一、更新丢失:
背景:隔离级别:READ-UNCOMMITED

由于取款事务回滚,导致把存款事务修改的数据覆盖了。出现了更新丢失。
解决:因InnoDB会给我们加锁,所以当今这种情况不会发生。
二、脏读
背景:隔离级别:READ-UNCOMMITTED
由于读了未提交事务的数据,导致异常。
某人有1000元。
取款事务读到了1000。
取款事务扣100元剩900元。
存款事务读到了900元。
取款事务回滚了,剩1000 。
存款事务用读到的900+1000,剩1900元。
取款取消了,导致最终存款少了100。
解决:设置隔离级别:set session transation isolation level read committed;
隔离级别:READ-COMMITTED
某人有1000元。
取款事务读到了1000。
取款事务扣100元剩900元。
存款事务读到了1000元。
取款事务回滚了,剩1000 。
存款事务用读到的1000+1000,剩2000元。
取款取消了,未影响数据的正确性。
三、不可重复读
背景:隔离级别:READ-COMMITTED
事务A多次读数据,事务B在事务A多次读的过程中修改了数据并提交了。导致事务A每次读到的数据不一样。
事务A读到了1000元。
事务B读到了1000元。加1000,剩2000。
事务A又读到了1000元。(因隔离级别为READ-COMMITTED)
事务B提交。
事务A读到了2000。导致前后两次读到的数据不一样。
解决:设置隔离级别:set session transation isolation level repeatable read;
隔离级别:REPEATABLE-READ
事务A读到了1000元。
事务B读到了1000元。加1000,剩2000。
事务A又读到了1000元。(因隔离级别为READ-COMMITTED)
事务B提交。
事务A读到了1000。前后两次读到的数据一样。
即:当前事务不管别的事务怎么修改提交,自己还是用的自己那份数据。
四、幻读
背景:隔离级别:REPEATABLE-READ
事务A当前查询到了4条数据。
事务B 插入\删除 一条数据,提交。
事务A更新数据,发现更新了5条\3条。好像出现了幻觉。
解决:设置隔离级别:set session transation isolation level serializable;
隔离级别:SERIALIZABLE
即:串行。但是会影响并发效率。
总结

边栏推荐
- Gtest之TEST宏的用法
- LAN communication process in the same network segment
- leaflet 地图
- [postman] dynamic variable (also known as mock function)
- Introduction to promql of # yyds dry goods inventory # Prometheus
- (5) Explanation of yolo-v3 core source code (3)
- Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
- Hongliao Technology: Liu qiangdong's "heavy hand"
- 黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
- Seven imperceptible truths in software testing
猜你喜欢

【Postman】Collections-运行配置之导入数据文件

Sqlmap tutorial (III) practical skills II

10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块

【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能

MySQL之数据类型
![[wechat applet] build a development tool environment](/img/f6/51f97b1c927337b34c5b3a4207abb4.png)
[wechat applet] build a development tool environment

技术分享 | 常见接口协议解析

H3C firewall rbm+vrrp networking configuration

CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全

【Postman】测试(Tests)脚本编写和断言详解
随机推荐
关于 PHP 启动 MongoDb 找不到指定模块问题
PAT(乙级)2022年夏季考试
isam2运行流程
Interface test: what are the components of the URL in fiddler
「 WEB测试工程师 」岗位一面总结
GTSAM中李群的運用
技术分享 | 常见接口协议解析
Web界面元素的测试
Testing and debugging of multithreaded applications
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
Investment strategy discussion and market scale prediction report of China's solid state high power amplifier industry from 2022 to 2028
LeetCode 739. 每日温度
[course notes] Compilation Principle
JDBC Requset 对应内容及功能介绍
[web security] nodejs prototype chain pollution analysis
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[Thesis code] SML part code reading
H3C firewall rbm+vrrp networking configuration
[postman] collections configuration running process