当前位置:网站首页>数据库隔离级别
数据库隔离级别
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
即:串行。但是会影响并发效率。
总结
边栏推荐
- Nodejs realizes the third-party login of Weibo
- 【eolink】PC客户端安装
- Manhattan distance and Manhattan rectangle - print back font matrix
- leaflet 地图
- [Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
- C language bubble sort
- Thoughts on data security (Reprint)
- 《卓有成效的管理者》读书笔记
- isam2运行流程
- Clock in during winter vacation
猜你喜欢
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
Idea new UI usage
【Postman】Monitors 监测API可定时周期运行
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
Application du Groupe Li dans gtsam
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
单元测试的意义
[web security] nodejs prototype chain pollution analysis
nodejs实现微博第三方登录
LeetCode 731. 我的日程安排表 II
随机推荐
P问题、NP问题、NPC问题、NP-hard问题详解
Clock in during winter vacation
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
[paper reading] nflowjs: synthetic negative data intensive anomaly detection based on robust learning
JDBC Requset 对应内容及功能介绍
How Huawei routers configure static routes
[course notes] Compilation Principle
【无App Push 通用测试方案
Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028
C language bubble sort
IPv6 comprehensive experiment
Postman核心功能解析-参数化和测试报告
公司视频加速播放
Luogu p1460 [usaco2.1] healthy Holstein cows
Application du Groupe Li dans gtsam
LAN communication process in the same network segment
Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
【Postman】Collections-运行配置之导入数据文件
把el-tree选中的数组转换为数组对象
J'ai un chaton.