当前位置:网站首页>mysql事务和隔离级别
mysql事务和隔离级别
2022-07-02 05:40:00 【斑马!】
目录
1. 事务的概念和特效
1.1 事务
事务由单独单元的一个或者多个SQL语句组成,在这个单元中,每个SQL语句是相互依赖的。而整个单独单元作为一个不可分割的整体,如果单元中某条SQL语句一旦执行失败或者产生错误,整个单元将会回滚。所有受影响的数据将返回到事务开始以前的状态;如果单元中的所有SQL语句均执行成功,则事务被顺利执行。
1.2 事务的acid属性
原子性:原子性是指事务是一个不可分割的工作单位,事务中的操作要么都发生,要么都不发生。
一致性:事务必须使数据库从一个一致性状态变换到另外一个一致性状态。
隔离性:事务的隔离性是指一个事务的执行不能被其他事务干扰,即一个事务内部的操作及其使用的数据对并发的其他事务是隔离的,并发执行的各个事务之间不能互相干扰。
持久性:持久性是指一个事务一旦被提交,它对数据库中的数据的改变就是永久性的,接下来的其他操作和数据库故障不应该对其有任何影响。
1.3 多个事务导致的并发问题
对于同时运行的多个事务,当这些事务访问数据库中相同的数据时候,如果没有采取必要的隔离机制,就会导致各种并发问题;
脏读:对于两个事务 T1, T2, T1 读取了已经被 T2 更新但还没有被提交的字段.之后, 若 T2 回滚, T1读取的内容就是临时且无效的。
不可重复读:对于两个事务t1,t2,如果t1读取了一个字段,任何t2更新了该字段,之后,t1再次读取同一个字段,值就不同了。
幻读:对于两个事务t1,t2,如果t1从一个表中读取了一个字段,然后t2在该表中插入了一些新的行,之后,如果t1再次读取同一个表,就会多处几行。
2.事务处理
- 事务(transaction) 一组SQL语句
- 退回(rollback)撤销执行SQL语句的过程
- 提交(commit) 将为执行的SQL语句写入数据库表
- 保留点(savepoint) 临时存储点,用于发布退回
3. 事务的隔离级别
1)数据库事务的隔离性:数据库系统必须具有隔离并发运行各个事务的能力,使得他们不会互相影响,避免各种并发问题;
2)一个事务与其他事务隔离的程度称为隔离级别。数据库规定了多种事务隔离级别,不同隔离级别对应不同的干扰程度,隔离级别越高,数据一致性就越好,但并发行越弱。
3)4种隔离级别

4)设置隔离级别
- set transaction isolation level read committed :设置当前mysql连接的隔离级别;
- set global transaction isolation level read committed: 设置数据库系统的全局的隔离级别;
边栏推荐
- Go language web development is very simple: use templates to separate views from logic
- Disable access to external entities in XML parsing
- Opencv LBP features
- Fabric. JS iText sets the color and background color of the specified text
- brew install * 失败,解决方法
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- Taskbar explicit / implicit toggle function
- Importation de studio visuel
- Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
- Fabric. JS free draw rectangle
猜你喜欢

VSCode paste image插件保存图片路径设置

idea开发工具常用的插件合集汇总

Fabric. JS iText set italics manually

【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond

Win10 copy files, save files... All need administrator permission, solution

3D printer G code command: complete list and tutorial

Gee series: Unit 1 Introduction to Google Earth engine

ThreadLocal memory leak

RGB 无限立方体(高级版)

操作符详解
随机推荐
在线音乐播放器app
Fabric. JS background is not affected by viewport transformation
RNN recurrent neural network
Pytorch Basics
【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
5g market trend in 2020
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
Detailed explanation of Pointer use
Gee: create a new feature and set corresponding attributes
Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]
460. LFU cache bidirectional linked list
Php/js cookie sharing across domains
Financial portal related information
Software testing learning - day 4
Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan
Common protocols and download paths of NR
Zzuli:1067 faulty odometer
Fabric. JS three methods of changing pictures (including changing pictures in the group and caching)
中小型项目手撸过滤器实现认证与授权
Huawei Hongmeng OS, is it OK?