当前位置:网站首页>Mysql database foundation: TCL transaction control language
Mysql database foundation: TCL transaction control language
2022-06-30 10:43:00 【Long lasting bangbangjun】
List of articles
Business
1、 brief introduction
One or a group of sql Statements form an execution unit , This execution unit is either all executed , Or none at all .
The whole individual unit as an indivisible whole , If one of the units sql Once the statement fails to execute or produces an error , The whole unit will Roll back .
All affected data will be returned to the state before the start of the transaction ;
If all of the units sql Statements are executed successfully , Then the transaction is executed smoothly
Roll back : Simply put, undo the operation
2、 The transaction ACID attribute *
1、 Atomicity (Atomicity)
Atomicity means that a transaction is an indivisible unit of work , Either the operations in the transaction occur , Or none at all
2、 Uniformity (Consistency)
Consistency means that a transaction must change a database from one consistency state to another
3、 Isolation, (Isolation)
Transaction isolation means that the execution of one transaction cannot be interfered by other transactions , And the operations and data used within a transaction are isolated from other concurrent transactions , Concurrent transactions cannot interfere with each other
4、 persistence (Durability)
Persistence means that once a transaction is committed , It changes the data in the database permanently , Other subsequent operations and database failures should not have any impact on it
3、 The creation of transactions
Implicit transaction : The transaction has no obvious opening and closing marks . such as :insert、update、delete sentence
According to the transaction : A transaction has distinct open and end tags . Use the premise : Auto submit must be disabled first (set autocommit=0;)
Use steps :
1、 Open transaction :
# Set the auto submit function to disabled
set autocommit=0;
# Open transaction , If the above statement is used, it can be omitted
start transaction; # Optional
2、 Write... In a transaction sql sentence (select、insert、update、delete)
3、 End the business
commit; # Submit
rollback; # Roll back
4、 Concurrency issues
4.1 describe
For multiple transactions running simultaneously , When these transactions access the same data in the database , If necessary isolation mechanism is not adopted , It can lead to various concurrency problems :
(1) Dirty reading : For two things T1,T2,T1 Read has been T2
to update But after the fields that have not been submitted , if T2 Roll back , be T1 The read content is temporary and invalid .
(2) It can't be read repeatedly : For two things T1,T2,T1 Read a field , then T2 After updating this field ,T1 Read the same field again , The value read is different .
(3) Fantasy reading : For two things T1,T2,T1 Read a field from a table , then T2 In the table Insert After adding some new lines , If T1 Read the same table again , There will be more lines .
4.2 Set the isolation level to solve the concurrency problem
Set the isolation level to organize the generation of concurrency problems .
Isolation level : The degree to which a transaction is isolated from other transactions is called the isolation level , Different isolation levels should respond to different interference intensities , Higher isolation level , The better the data consistency , But the less concurrent .
Four transaction isolation levels provided by the database
(1)READ UNCOMMITTED( Read uncommitted data )
Allow transactions to read changes that are not committed by other transactions . Dirty reading 、 The problems of nonrepeatable reading and unreal reading will arise .
(2)READ COMMITTED( Read submitted data )
Only transactions are allowed to read changes that have been committed by other transactions . Avoid dirty reading , But the problems of unrepeatability and unreal reading may still arise .
(3)REPEATABLE READ( Repeatable )
Make sure that transactions can read the same value from a field multiple times . During the duration of this transaction , Prohibit other transactions from updating this field , It can avoid dirty reading and non repeatability , But the problem of unreal reading cannot be solved .
(4)SERIALIZABLE( Serialization )
Make sure that transactions can read the same rows from a table . During the duration of this transaction , Prevent other transactions from inserting into the table , Update and delete operations , All concurrency problems can be avoided , But the performance is very low .
oracle Database supported 2 Transaction isolation level in :READ COMMITED,SERIAlIZABLE. The default is READCOMMITED
mysql The database supports four isolation levels , The default is REPEATABLE READ
4.3 Set isolation level
- View the current isolation level
select @@transaction_isolation;
- Change the isolation level
Set up current mysql Isolation level of the connection
# Change the isolation level to read uncommitted Level
set session transaction isolation level read uncommitted;
Set the global isolation level of the database system
set global transaction isolation level read committed;
5、 Roll back
Use savepoint Set rollback point
set autocommit = 0;
start transaction;
delete from account where id = 25;
savepoint a; # Set the savepoint
delete from account where id = 28;
rollback to a; # Roll back to savepoint
perform rollback to a After this sentence , The operation after the specified rollback point will be automatically undone
6、 Use... In transactions delete and truncate The difference between
delete Support rollback ,truncate Rollback is not supported
边栏推荐
- 19:00 p.m. tonight, knowledge empowerment phase 2 live broadcast - control panel interface design of openharmony smart home project
- Highlight display of Jinbei LB box, adhering to mini special effects
- 苹果5G芯片被曝研发失败,QQ密码bug引热议,蔚来回应做空传闻,今日更多大新闻在此...
- Robotframework learning notes: environment installation and robotframework browser plug-in installation
- CSDN daily one practice 2021.11.06 question 1 (C language)
- Skill sorting [email protected]+adxl345+ Motor vibration + serial port output
- What is the real performance of CK5, the king machine of CKB?
- CVPR 2022 | 清华&字节&京东提出BrT:用于视觉和点云3D目标检测的桥接Transformer
- 机器学习面试准备(一)KNN
- SGD有多种改进的形式,为什么大多数论文中仍然用SGD?
猜你喜欢

Musk has more than 100 million twitter fans, but he has been lost online for a week
[email protected] somatosensory manipulator"/>Skill combing [email protected] somatosensory manipulator
[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled"/>技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled

GeoffreyHinton:我的五十年深度学习生涯与研究心法

Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
[email protected]+adxl345+电机震动+串口输出"/>技能梳理[email protected]+adxl345+电机震动+串口输出

CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection
[email protected]在oled上控制一条狗的奔跑"/>技能梳理[email protected]在oled上控制一条狗的奔跑

Criu enables hot migration

从0使用keil5软件仿真调试GD32F305
随机推荐
最新SCI影响因子公布:国产期刊最高破46分!网友:算是把IF玩明白了
Overview of currency
IPhone address book import into Excel
Using LVM to resize partitions
mysql数据库基础:TCL事务控制语言
GD32 RT-Thread flash驱动函数
Circuit breaker hystrixcircuitbreaker
Smith chart view of semi steel coaxial RF line and RF line matching calibration of network analyzer e5071c
半钢同轴射频线的史密斯圆图查看和网络分析仪E5071C的射频线匹配校准
ArcGIS Pro + PS 矢量化用地规划图
Leetcode question brushing (IV) -- greedy thought (go Implementation)
The rising star of Goldshell STC box
mysql数据库基础:约束、标识列
GD32 RT-Thread OTA/Bootloader驱动函数
Gd32 RT thread flash driver function
技能梳理[email protected]基于51系列单片机的智能仪器教具
Leetcode question brushing (II) -- sorting (go Implementation)
Gd32 RT thread ota/bootloader driver function
Koreano essential creates a professional style
Node environment configuration