当前位置:网站首页>【数据库】事务
【数据库】事务
2022-06-30 05:51:00 【今夜鸣风】
概念:事务是指一个用户定义的数据库操作序列,这个事务要么全部执行要不不执行。
事务特性:ACID
原子性、一致性、隔离性,持久性。
原子性(Atomicity):
是不可分割的最小操作单位,要么同时成功,要么同时失败
一致性(Consistency):
保证数据的状态操作前和操作后保持一致
隔离性(Isolation):
多个事务同时操作相同数据库的同一个数据时,一个事务的执行不受另外一个事务的干扰
持久性(Durability):
当事务提交或回滚后,数据库会持久化的保存数据
事务操作步骤
1. 开启事务
2. 编写事务逻辑操作单元
3. 提交事务或回滚事务
事务分类:
* 隐式事务:没有明显的开启和结束事务的标志
* insert、update、delete语句本身就是一个事务
* 显式事务:具有明显的开启和结束事务的标志
1. 取消自动提交事务:set autocommit=0;
2. 开启事务:start transaction;
3. 提交或回滚事务:
- commit;
- rollback;
事务的隔离级别(面试常考):
* 事务并发问题是如何产生的?
- 当多个事务同时操作同一个数据库的相同数据时
* 事务并发问题
- 脏读:一个事务读取到了另外一个事务未提交的数据
- 不可重复读:同一个事务中,多次读取到的数据不一致
- 幻读:一个事务读取数据时,另外一个事务进行更新,导致第一个事务读取到了没有更新的数据
* 处理事务并发问题,设置事务隔离级别
- READ UNCOMMITTED
- READ COMMITTED:可以避免脏读
- REPEATABLE READ:可以避免脏读、不可重复读和一部分幻读
- SERIALIZABLE:可以避免脏读、不可重复读和幻读
* 注意:隔离级别从小到大安全性越来越高,但是效率越来越低
* 设置隔离级别
- set session|global transaction isolation level 隔离级别名;
* 查看隔离级别
- select @@tx_isolation;
边栏推荐
- [secretly kill little partner pytorch20 days] - [day4] - [example of time series data modeling process]
- leetcode763. Divide letter interval
- [chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point
- MySQL存储系统
- Luogup2756 pilot pairing scheme problem (maximum flow)
- El table lazy load refresh
- Stack overflow caused by C # using protobuf stack overflow
- Leetcode search insert location
- OpenCL线程代数库ViennaCL的使用
- D. Big Brush
猜你喜欢
![[Alibaba cloud] student growth plan answers](/img/34/cba975c0960d5595433adcb23f6e64.jpg)
[Alibaba cloud] student growth plan answers

Leetcode search insert location

86. 分隔链表

What are membrane stress and membrane strain

图扑软件基于钻孔数据的三维地质模型可视化

Sword finger offer 18 Delete the node of the linked list
![[secretly kill little partner pytorch20 days] - [day4] - [example of time series data modeling process]](/img/f3/e51cb80f838faba8dfd90596d6e57b.jpg)
[secretly kill little partner pytorch20 days] - [day4] - [example of time series data modeling process]

UE4_ Editor development: highlight the UI making method according to the assets dragged by the mouse (1)

inno setup 最简单的自定义界面效果

MySQL advanced (Advanced SQL statement)
随机推荐
86. separate linked list
【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点
Xi'an Jiaotong 21st autumn economics online homework answer sheet (III) [standard answer]
Codeforces B. MEX and Array
Xi'an Jiaotong 21st autumn online expansion resources of online trade and marketing (III) [standard answer]
Uboot reads the DDR memory size by sending 'R' characters through the terminal
【LeetCode】236. Nearest common ancestor of binary tree
Use of tornado template
Using lazy < t > in C # to realize singleton mode in WPF
炒股用指南针开户交易安全吗?
Golden code of programmer interview
C. Divan and bitwise operations
OpenCL线程代数库ViennaCL的使用
MySQL advanced (Advanced SQL statement)
Delete the repeating elements in the sorting list (simple questions)
D. Big Brush
动态规划--怪盗基德的滑翔翼
Answer sheet for online assignment of "motor and drive" of Xijiao 21 autumn (IV) [standard answer]
Leetcode56. consolidation interval
1380. lucky numbers in matrices