当前位置:网站首页>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
边栏推荐
- VPS installation virtualmin panel
- Enter the smart Park, and change begins here
- QQ group collection
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
- Video analysis
- Customized version of cacti host template
- About the use of URL, href, SRC attributes
- Snowflake won the 2021 annual database
- Iframe to only show a certain part of the page
- (August 10, 2021) web crawler learning - Chinese University ranking directed crawler
猜你喜欢
2021-08-09
Application of slice
Ultimate bug finding method - two points
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 5
Enter the smart Park, and change begins here
Clion configuration of opencv
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
Practical dry goods: deploy mini version message queue based on redis6.0
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
Simple understanding of seesion, cookies, tokens
随机推荐
Recommend a cool geospatial data visualization tool with low code
Xshell's ssh server rejected the password, failed to skip publickey authentication, and did not register with the server
Some summaries of the 21st postgraduate entrance examination 823 of network security major of Shanghai Jiaotong University and ideas on how to prepare for the 22nd postgraduate entrance examination pr
(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
First knowledge of spark - 7000 words +15 diagrams, and learn the basic knowledge of spark
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
SAP ui5 date type sap ui. model. type. Analysis of the display format of date
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 5
os. Path built-in module
[Android reverse] function interception instance (③ refresh CPU cache | ④ process interception function | ⑤ return specific results)
Process communication and thread explanation
World document to picture
QQ get group link, QR code
Games101 Lesson 8 shading 2 Notes
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Single spa, Qiankun, Friday access practice
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
LxC shared directory permission configuration