当前位置:网站首页>[MySQL] understanding of transactions
[MySQL] understanding of transactions
2022-06-25 08:45:00 【Xiao AI ~】
1. What is business
Transaction is actually a complete business logic . It is the smallest unit of work and cannot be further divided .
2. How to use transactions
The only transaction is DML You can use , Other statements have nothing to do with transactions , Because only DML Statement is to add data in the database table 、 Delete 、 Changed . As long as your operation involves the increase of data 、 Delete 、 Change , Then we must consider the safety issue .
3. Specific use of transactions
1. The default state of the transaction
The default state of a transaction is active commit , Whenever we execute a DML Statement will automatically help us submit sql sentence , Can't roll back .
2. Transaction processing status
There are two transaction processing states :1. Submit (commit)、2. Roll back (rollback)
# The use of transactions is as follows :
START TRANSACTION; # Open transaction ( take mysql The status of is set to manual submission )
INSERT INTO tab_identity(ID,`NAME`,`money`) VALUES (NULL,' Piglets ',500); # Execute a random DML sentence
# Processing status
ROLLBACK; # Roll back
#COMMIT # Submit
* 4. The nature of transactions
There are 4 The two features are :
A: Atomicity
Explain that transactions are the smallest unit of work . Can not be further divided .
C: Uniformity
All transactions require , In the same transaction , All operations must succeed at the same time , Or fail at the same time , To ensure data consistency .
I: Isolation,
A Business and B There is some isolation between transactions
A When a transaction operates on a table, another transaction B What will happen if you also operate this table .
D: persistence
A guarantee of the end of the transaction , Transaction submission , It is equivalent to saving data not saved to the hard disk to the hard disk !
* 5. The isolation level of the transaction
What are the isolation levels between transactions ?4 Isolation
1. Read uncommitted :read uncommitted ( Minimum isolation level ) 《 Uncommitted data can be read 》
What is read uncommitted ?
Business A Can read to transaction B Uncommitted data , The problem with this isolation level is : Dirty reading !(Dirty read) We say we read dirty numbers
2. Read submitted :read committed《 You can only read after submitting 》
What is read committed
Business A Only transactions can be read B Data after submission , This isolation level resolves dirty reads . This level of isolation does not allow data to be read repeatedly , The data read every time is absolutely true .
3. Repeatable :repeatable read 《 You can't read it after submitting , Always read the data when the transaction was just started 》
Business A After opening , No matter how long , Every time in the transaction A Data read from , Will not be affected by the outside world , Even if the data has changed , Business A The read data will not change , This is repeatable reading . It solves the problem of non repeatable data reading , But every time the data is read, it is an illusion , Not true enough !
4 . serialize / Serialization :serializable ( The highest isolation level )
This is the highest isolation level and the lowest efficiency , Solved all the problems , This isolation level indicates that transactions are queued , Can't be concurrent
Check the isolation level
-- Check the isolation level
select @@tx_isolation;
-- Change the isolation level
set GLOBAL TRANSACTION ISOLATION LEVEL Isolation level ;
边栏推荐
- Check whether the point is within the polygon
- Various synchronous learning notes
- 关于I/O——内存与CPU与磁盘之间的关系
- About i/o -- the relationship between memory and CPU and disk
- 配置、软件配置项、软件配置管理项辨析
- View all listening events on the current page by browser
- [summary] 1361- package JSON and package lock JSON relationship
- Getting to know the generation confrontation network (12) -- using pytoch to build wgan-gp to generate handwritten digits
- InfluxDB时序数据库
- What does openid mean? What does "token" mean?
猜你喜欢

Retrieval model rough hnsw

Exchange: manage calendar permissions

A 35 year old Tencent employee was laid off and sighed: a suite in Beijing, with a deposit of more than 7 million, was anxious about unemployment

How to solve the 10061 error of MySQL in Linux

wav文件(波形文件)格式分析与详解

各种同步学习笔记

How to design test cases

Exchange:管理日历权限

C language "recursive series": recursive implementation of 1+2+3++ n

cazy长安战役八卦迷宫
随机推荐
故障:Outlook 收发邮件时的 0x800CCC1A 错误
Nips 2014 | two stream revolutionary networks for action recognition in videos reading notes
各种同步学习笔记
How to calculate the independence weight index?
What is the difference between TP5 and tp6?
Meaning of Jieba participle part of speech tagging
声纹技术(五):声纹分割聚类技术
Sharepoint:sharepoint server 2013 and adrms Integration Guide
RTOS 多线程下hardfault问题总结
How to design test cases
Getting to know the generation confrontation network (12) -- using pytoch to build wgan-gp to generate handwritten digits
What is the role of software validation testing? What is the price of the confirmation test report?
What does openid mean? What does "token" mean?
城鏈科技平臺,正在實現真正意義上的價值互聯網重構!
On which platform is it safe to buy shares and open an account? Ask for sharing
如何成为一名软件测试高手? 月薪3K到17K,我做了什么?
About i/o -- the relationship between memory and CPU and disk
35岁腾讯员工被裁员感叹:北京一套房,存款700多万,失业好焦虑
Stimulsoft ultimate presents reports and dashboards
声纹技术(七):声纹技术的未来