当前位置:网站首页>【数据库】事务
【数据库】事务
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;
边栏推荐
- Answer sheet for online assignment of "motor and drive" of Xijiao 21 autumn (IV) [standard answer]
- OSPF - authentication and load balancing summary (including configuration commands)
- Redistemplate common method summary
- How to print pthread_ t - How to print pthread_ t
- Xijiao 21 autumn "motor and drive" online homework answer sheet (I) [standard answer]
- Rotating frame target detection mmrotate v0.3.1 learning configuration
- luoguP2756 飞行员配对方案问题(最大流)
- At the age of 32, I fell into a middle-aged crisis and finally quit naked...
- UE4_ Editor UMG close window cannot destroy UMG immediately
- 超简单 STM32 RTC闹钟 时钟配置
猜你喜欢
Xctf attack and defense world crypto advanced area
How does WPS cancel automatic numbering? Four options
强烈推荐十几款IDEA开发必备的插件
声网,站在物联网的“土壤”里
How to prevent source code leakage in enterprises and institutions
Sword finger offer 18 Delete the node of the linked list
Transfer the token on the matic-erc20 network to the matic polygon
[chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point
We strongly recommend more than a dozen necessary plug-ins for idea development
旋转框目标检测mmrotate v0.3.1 训练DOTA数据集(二)
随机推荐
Simple use of qlistview of QT (including source code + comments)
Rotating frame target detection mmrotate v0.3.1 learning configuration
ECS deployment web project
Bev instance prediction based on monocular camera (iccv 2021)
[Alibaba cloud] student growth plan answers
At the age of 32, I fell into a middle-aged crisis and finally quit naked...
Qt之QListView的简单使用(含源码+注释)
[road of system analyst] collection of wrong topics in Project Management Chapter
Visualization of 3D geological model based on borehole data by map flapping software
Use of tornado template
How does WPS cancel automatic numbering? Four options
86. 分隔链表
Xi'an Jiaotong automation control theory test simulation question [standard answer]
Sword finger offer 18 Delete the node of the linked list
Database SQL language 06 single line function
How to print pthread_ t - How to print pthread_ t
Xiaosha's lunch
Xijiao 21 autumn "motor and drive" online homework answer sheet (III) [standard answer]
聲網,站在物聯網的“土壤”裏
动态规划--怪盗基德的滑翔翼