当前位置:网站首页>数据库隔离级别
数据库隔离级别
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
即:串行。但是会影响并发效率。
总结
边栏推荐
猜你喜欢
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
Embedded point test of app
Arrays and collections
技术分享 | 常见接口协议解析
异常检测方法总结
Novice entry SCM must understand those things
IPv6 comprehensive experiment
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
Manhattan distance and Manhattan rectangle - print back font matrix
随机推荐
LAN communication process in the same network segment
【Postman】动态变量(也称Mock函数)
Sqlmap tutorial (III) practical skills II
黑猫带你学UFS协议第4篇:UFS协议栈详解
How Huawei routers configure static routes
[C language syntax] the difference between typedef struct and struct
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
【eolink】PC客户端安装
H3C S5820V2_ Upgrade method after stacking IRF2 of 5830v2 switch
【Postman】Collections配置运行过程
Detailed explanation of BF and KMP
[web security] nodejs prototype chain pollution analysis
数学三大核心领域概述:几何
LeetCode 731. 我的日程安排表 II
公司视频加速播放
How to use the container reflection method encapsulated by thinkphp5.1 in business code
2022 software testing workflow to know
Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
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