当前位置:网站首页>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 .
边栏推荐
- Critical applications and hyper converged infrastructure: the time has come
- Detailed explanation of commissioning methods and techniques
- train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
- 开源了!文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
- MIT-6874-Deep Learning in the Life Sciences Week6
- 事件委托的使用与说明》
- 孙安民作品《莲花净心》数字藏品上线长城数艺
- Is the jar package for the project or the project for the jar package
- Launch of Rural Revitalization public welfare fund and release of public welfare bank for intangible cultural heritage protection of ancient tea tree
- The famous painter shiguoliang's "harvest season" digital collection was launched on the Great Wall Digital Art
猜你喜欢

C语言实现扫雷游戏,附详解及完整代码

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

Hospital integration platform super fusion infrastructure transformation scheme

调试方法和技巧详解

Appium automation test foundation - ADB shell command

NLopt--非线性优化--原理介绍及使用方法

Appium automation test foundation - 12 Introduction to appium automated testing framework
![[AGC] build service 3- authentication service example](/img/32/44547c00476a055557dd1790e18849.png)
[AGC] build service 3- authentication service example

UAV project tracking record 83 -- PCB diagram completion

MIT-6874-Deep Learning in the Life Sciences Week6
随机推荐
Js获取指定字符串指定字符位置&指定字符位置区间的子串【简单详细】
How do databases go to the enterprise cloud? Click to view the answer
ModuleNotFoundError: No module named ‘_ swigfaiss‘
Add / delete query of topic
光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述
unable to convert expression into double array
‘Failed to fetch current robot state‘ when using the ‘plan_ kinematic_ path‘ service #868
Appium自动化测试基础 — 12.APPium自动化测试框架介绍
机械臂速成小指南(五):末端执行器
MIT-6874-Deep Learning in the Life Sciences Week4
LVS load balancing
How to build a private cloud and create a hybrid cloud ecosystem?
2022第六季完美童模 合肥赛区 初赛圆满落幕
Launch of Rural Revitalization public welfare fund and release of public welfare bank for intangible cultural heritage protection of ancient tea tree
Quick completion guide for mechanical arm (V): end effector
基于强化学习的股票量化交易Automated-Stock-Trading-Ensemble-Strategy
Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home
Input limit input
一些国内镜像源
Automated stock trading ensemble strategy based on Reinforcement Learning