当前位置:网站首页>MySQL index, transaction and storage engine of database (2)
MySQL index, transaction and storage engine of database (2)
2022-06-30 10:16:00 【thengsd】
Catalog
One 、MySQL Business
1、 Concept of transactions
- A transaction is a mechanism 、 A sequence of operations , Contains a set of database operation commands , And all the commands as a whole to submit or revoke the operation request to the system , That is, this set of database commands is either executed , Either not .
- A transaction is an indivisible unit of work logic , When performing concurrent operations on a database system , Transactions are the smallest unit of control .
- Transaction is suitable for the scenario of multi-user operating database system at the same time , Like a bank 、 Insurance companies and securities trading systems, etc .
- Transactions ensure the consistency of data through the integrity of transactions .
Simply speaking , Transaction , It's a sequence of operations , These operations are either performed , Either not , It is an indivisible unit of work .
2、 The transaction ACID characteristic
ACID, In a reliable database management system (DBMS) in , Business (transaction) It should have four characteristics : Atomicity (Atomicity)、 Uniformity (Consistency)、 Isolation, (Isolation)、 persistence (Durability). These are the characteristics of a reliable database .
( One ) Atomicity
- A transaction is an indivisible unit of work , Either the operations in the transaction occur , Or none at all .
- A transaction is a complete operation , The elements of a transaction are indivisible .
- All elements in a transaction must be committed or rolled back as a whole .
- If any element in the transaction fails , Then the whole transaction will fail .
- for example :
- A to B transfer 100 Only the deduction statement was executed when the amount of RMB was RMB , Just submitted ;
- If there is a sudden power failure ,A The account has been deducted ,B The account didn't receive the additional payment , It can cause disputes in life .
- In this case, the atomicity of transactions is needed to ensure that all transactions are executed , Or they don't do it .
( Two ) Uniformity
- Before and after the transaction , The database integrity constraint is not broken .
- When the transaction is complete , The data must be in a consistent state .
- Before the transaction starts , The data stored in the database is in a consistent state .
- In an ongoing transaction , The data may be in an inconsistent state .
- When the transaction completes successfully , The data must return to the known consistent state again .
- for example :
- For bank transfers , Whether the transaction succeeds or fails , You should make sure that after the transaction, the table A and B The total amount of deposit is the same as before .
( 3、 ... and ) Isolation,
Isolation concept :
- In a concurrent environment , When different transactions manipulate the same data at the same time , Each transaction has its own full data space .
- A transaction that modifies data can access that data before another transaction that uses the same data starts , Or access the data after another transaction using the same data ends .
Classification of interactions between transactions :
- Dirty reading : One transaction reads uncommitted data from another transaction , And it's possible to roll back this data .
- It can't be read repeatedly : Two identical queries in a transaction return different data . This is caused by the commit of other transaction modifications in the system during query .
- Fantasy reading : A transaction modifies the data in a table , This modification involves all data rows in the table . meanwhile , Another transaction also modifies the data in this table , This modification is to insert a new row of data into the table . that , The user operating the previous transaction will find that there are no modified data rows in the table , It's like an illusion .
- Lost update : Two transactions read the same record at the same time ,A Change the record first ,B Also modify the record (B I do not know! A A modified ),B After submitting the data B The result of the modification covers A Modification results of .
Mysql And the isolation level of things :
- read uncommitted ( Read uncommitted data ) : Don't solve dirty reading
- read committed( Read submitted data ) : Can solve dirty reading
- repeatable read( Reread read ): Can solve dirty reading and It can't be read repeatedly —mysql default
- serializable( Serialization ): Can solve Dirty reading It can't be read repeatedly and Fantasy reading — It's like a lock table
mysql The default transaction level is repeatable read , and Oracle and SQL Server yes read committed .
( Four ) Transaction related query commands
- Query global transaction isolation level :

- Query session transaction isolation level :

- Set the global transaction isolation level :

- Set session transaction isolation level :

3、 persistence
- After the transaction is completed , Changes made by the firm to the database are persisted in the database , It will not be rolled back .
- No matter whether the system fails or not , The result of the transaction is permanent .
- Once the transaction is committed , The effect of the transaction is permanently preserved in the database .
summary : In transaction management , Atomicity is the foundation , Isolation is the means , Consistency is the purpose , Persistence is the result .
4、 Transaction control statement
( One ) Create table , And add data

( Two ) Test commit transactions


( 3、 ... and ) Test rollback transactions


( Four ) Test multi point rollback



5、 Use set Set control transaction


If Auto submit is not turned on , The name of the current session connection mysql All of the operations are treated as a transaction until you type rollback|commit; The current transaction is closed . New before the end of the current transaction mysql Unable to read the operation result of any current session while connecting .
If Auto submit is on ,mysql Will put each sql Statement as a transaction , And then automatically commit.
Of course, whether it's on or off ,begin; commit|rollback; It's all independent business .
边栏推荐
- KOREANO ESSENTIAL打造气质职场范
- 李沐《动手学习深度学习》d2lbook环境搭建
- How can we have high performance and simple agility in the enterprise cloud on oracle?
- Rider does not prompt after opening unity script
- 新冠无情人有情,芸众惠爱心善举暖人间——捐赠商丘市儿童福利院公益行动
- 磁悬浮3D灯
- The URL copied by the browser and pasted into the document is a hyperlink
- MIT-6874-Deep Learning in the Life Sciences Week6
- train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
- About the split and join operations of strings
猜你喜欢

Launch of Rural Revitalization public welfare fund and release of public welfare bank for intangible cultural heritage protection of ancient tea tree

长城数艺数字藏品平台发布创世徽章

Rider does not prompt after opening unity script

Force buckle 428 Serialize and deserialize n-tree DFS

磁悬浮3D灯

Plan the IT technology route for the new year? Let's learn about Gartner infrastructure hype cycle

华南产业集团发力数字经济,城链科技发布会成功召开

JUL简介

L'activité "Kunming City coffee map" a rouvert

Article content cannot be copied
随机推荐
Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect
“昆明城市咖啡地图”活动再度开启
“昆明城市咖啡地圖”活動再度開啟
OSError: [Errno 28] No space left on device
Koreano essential creates a professional style
孙安民作品《莲花净心》数字藏品上线长城数艺
2021-07-26
Plan the IT technology route for the new year? Let's learn about Gartner infrastructure hype cycle
G-Code 详解
Use and description of event delegation
train_de.py: error: argument --save_steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
MIT-6874-Deep Learning in the Life Sciences Week4
MIT-6874-Deep Learning in the Life Sciences Week6
‘Failed to fetch current robot state‘ when using the ‘plan_ kinematic_ path‘ service #868
Appium automation test foundation - ADB shell command
ModuleNotFoundError: No module named ‘_ swigfaiss‘
Description of event flow
9. cache optimization
Slf4j: failed to load class "org.slf4j.impl.staticloggerbinder"
How do databases go to the enterprise cloud? Click to view the answer