当前位置:网站首页>Interview question MySQL transaction (TCL) isolation (four characteristics)
Interview question MySQL transaction (TCL) isolation (four characteristics)
2022-07-04 12:10:00 【Peng_ zhj】
Technology provided by database ( Business )(TCL classification )
In actual business development , Some business operations need to access the database multiple times . One service needs to send multiple messages SQL Statement to the database . You need to
The operation of accessing the database is performed as a whole , Or all SQL All statements are executed successfully .
If one of them SQL Statement failure , Roll back the transaction , be-all SQL All statements failed to execute .
Such as transfers :
1 tom 1000
2 rose 1000
To complete the transfer business requires operations 2 Secondary database
1. from tom Subtract 500
update account set money = money - 500 where id = 1 ;
2. take 500 Add to rose Account number
update account set money = money + 500 where id = 2 ;
How to control 2 strip sql Not all statements are successful , Or all of them are failures ?
We have to use the transaction technology provided by the database to help us achieve our goal
The role of Transaction Technology :
You can control multiple steps of a complete thing
As long as one step goes wrong, the whole thing will fail , As long as all steps are successful, it is successful to control the current thing
demand : Create account table , Complete the control of transfer through transaction technology
The transaction operations
mysql By default, each item sql Statements are submitted automatically
But we have to make every one sql Statements have to be submitted manually , So turn off automatic submission
Do transaction operations :
start transaction; Start a transaction ( Turn off auto submit Manual submission is enabled )
update
update
commit; Commit the transaction and close the current manual commit
rollback; Rollback the transaction and close the current manual commit
Conclusion : We can put a business that needs to operate multiple databases into one transaction ,
It is convenient for us to manage every impact of this business on database data
When a business is completed, it needs to operate multiple sql At the time of statement You have to use transactions …
Interview questions : Four characteristics of transactions (ACID)
Atomicity (Atomicity)
A transaction is an indivisible unit , Either the operations in the transaction occur , Or none at all .
Uniformity (Consistency)
The integrity of the data before and after the transaction must be consistent
Isolation, (Isolation)
When multiple users access the database at the same time , The transaction of one user cannot be interfered by the transactions of other users , Data between multiple concurrent transactions should be isolated from each other , Don't influence each other .
persistence (Durability)
Once a transaction is committed , It changes the data in the database permanently
Isolation of transactions
problem : If the transaction does not have isolation , There will be reading problems when reading database data
1 Dirty reading : Read uncommitted data ( It must be avoided )
One transaction reads uncommitted data from another transaction
2 It can't be read repeatedly ( in the light of update Modified )
The data contents read twice in a transaction are inconsistent
3 Virtual reading / Fantasy reading ( in the light of insert Inserted )
The amount of data read twice in a transaction is inconsistent
solve
Isolation level of database
read uncommitted Read uncommitted The above three problems will happen
read committed(oracle Default ) Read submitted Avoid dirty reading
repeatable read(mysql Default ) Repeated reading Avoid dirty reading and non repeatable reading
serializable Serialization Avoid all problems
Inquire about mysql Isolation level
show variables like "%isolation%";
Set the isolation level of the transaction
set global transaction isolation level Level string ;
1. Read uncommitted ( The lowest level , None of the above can be guaranteed )
read uncommitted:
2. Read submitted ( It can avoid dirty reading .)
read committed
3. Repeatable ( Avoid dirty reading 、 Occurrence of non repeatable reading . mysql The default isolation level of )
repeatable read
4. Serialization ( Avoid dirty reading 、 It can't be read repeatedly 、 Fantasy reading ( Virtual reading ) What happened )
Use serializable Isolation level , A transaction is not completed , Other business SQL It can't be carried out
Security :serializable>repeatable read>read committed>read uncommitted:
efficiency :read uncommitted>read committed>repeatable read>serializable
In enterprise development , What must be avoided is dirty reading
mysql Data default level :repeatable read
oracle Data default level :read committed
边栏推荐
- Review of week 278 of leetcode II
- Video analysis
- Some tips on learning database
- Using terminal connection in different modes of virtual machine
- QQ one click cookie acquisition
- [solve the error of this pointing in the applet] SetData of undefined
- [Android reverse] function interception instance (③ refresh CPU cache | ④ process interception function | ⑤ return specific results)
- How to disable debug messages on sockjs stomp - how to disable debug messages on sockjs Stomp
- (August 9, 2021) example exercise of air quality index calculation (I)
- Single spa, Qiankun, Friday access practice
猜你喜欢

Here, the DDS tutorial you want | first experience of fastdds - source code compilation & Installation & Testing
![[solve the error of this pointing in the applet] SetData of undefined](/img/19/c34008fbbe1175baac2ab69eb26e05.jpg)
[solve the error of this pointing in the applet] SetData of undefined

Lecture 9

OSI seven layer model & unit

Leetcode: 408 sliding window median

DVC use case (VI): Data Registry
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9](/img/ed/0edff23fbd3880bc6c9dabd31755ac.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9

(2021-08-20) web crawler learning 2

Star leap plan | new projects are continuously being recruited! MSR Asia MSR Redmond joint research program invites you to apply!
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21](/img/73/4050a592fdd99bf06e8fd853b157b6.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
随机推荐
Common built-in modules
Using terminal connection in different modes of virtual machine
Force buckle 142 Circular linked list II
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
Login operation (for user name and password)
Googgle guava ImmutableCollections
QQ get group settings
Ternsort model integration summary
Lecture 9
How do std:: function and function pointer assign values to each other
Btrace tells you how to debug online without restarting the JVM
QQ group collection
Shift EC20 mode and switch
Review of week 278 of leetcode II
Method of setting default items in C # ComboBox control code
LxC shared directory permission configuration
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
priority_ queue
Simple understanding of seesion, cookies, tokens
Heartbeat error attempted replay attack