当前位置:网站首页>mysql的事务
mysql的事务
2022-07-17 05:09:00 【倫之】
一、事务的基本要素(ACID)
1、原子性(Atomicity):事务开始后所有操作,要么全部做完,要么全部不做,不可能停滞在中间环节。事务执行过程中出错,会回滚到事务开始前的状态,所有的操作就像没有发生一样。也就是说事务是一个不可分割的整体,就像化学中学过的原子,是物质构成的基本单位。
2、一致性(Consistency):事务开始前和结束后,数据库的完整性约束没有被破坏 。比如A向B转账,不可能A扣了钱,B却没收到。
3、隔离性(Isolation):同一时间,只允许一个事务请求同一数据,不同的事务之间彼此没有任何干扰。比如A正在从一张银行卡中取钱,在A取钱的过程结束前,B不能向这张卡转账。
4、持久性(Durability):事务完成后,事务对数据库的所有更新将被保存到数据库,不能回滚。
二、事务的并发问题
1、脏读:事务A读取了事务B更新的数据,然后B回滚操作,那么A读取到的数据是脏数据
2、不可重复读:事务 A 多次读取同一数据,事务 B 在事务A多次读取的过程中,对数据作了更新并提交,导致事务A多次读取同一数据时,结果 不一致。
3、幻读:系统管理员A将数据库中所有学生的成绩从具体分数改为ABCDE等级,但是系统管理员B就在这个时候插入了一条具体分数的记录,当系统管理员A改结束后发现还有一条记录没有改过来,就好像发生了幻觉一样,这就叫幻读。
小结:不可重复读的和幻读很容易混淆,不可重复读侧重于修改,幻读侧重于新增或删除。解决不可重复读的问题只需锁住满足条件的行,解决幻读需要锁表
边栏推荐
- 从20s优化到500ms,我用了这三招
- redis源码分析 2 迭代器
- Redis source code analysis skip table implementation
- vlookup函数的使用方法及实例
- C语言的宏定义
- 性能瓶颈查找-火焰图分析
- MySQL cache solution problem solving
- Solve the problem of inconsistent prediction effect between text detection training model and information model based on paddleocr
- SQL注入
- Excel template export of easypoi
猜你喜欢

Redis source code analysis 3 implementation of discontinuous traversal

ambari 2.7.5集成安装hue 4.6
![[first launch in the whole network] automatic analysis of JVM performance problems](/img/be/fb47c05b5d9410d4df7df25ed3aad0.png)
[first launch in the whole network] automatic analysis of JVM performance problems

操作系统常见面试题

Round robin schedule problem

指针数组&数组指针

Common interview questions of operating system

The first smart contract program faucet sol

Solve the problem of inconsistent prediction effect between text detection training model and information model based on paddleocr

Talk about 12 business scenarios of concurrent programming
随机推荐
Pointer advanced simple summary
【全网首发】一个月后,我们又从 MySQL 双主切换成了主-从
Round robin schedule problem
From 20s to 500ms, I used these three methods
数据可视化
Cesium 綁定鼠標事件和移除鼠標事件
Switch user mode, privileged mode, global mode, port mode
聊聊并发编程的12种业务场景
H5 how to obtain intranet IP and public IP
Questions d'entrevue courantes du système d'exploitation
2020-10-22
Markdown notes and related shortcut keys of typora
Easypoi之excel模板导出
Excel导入长数据末尾变000
2020-11-10
Beginner's Guide to learning penetration testing
UML (use case diagram, class diagram, object diagram, package diagram)
字幕文件与视频文件对不上的处理方式
Easypoi之excel多sheet导入
使用Flink SQL传输市场数据1:传输VWAP