当前位置:网站首页>MySQL transaction
MySQL transaction
2022-07-23 11:55:00 【Summer invasion bug planning】
MySQL Business
List of articles
Business (Transaction): A transaction is a complete business logic unit , Can not be further divided ;
example : Bank account transfer ,A Transfer the account to B Account 10000, You need to perform two update sentence
update Table name set Field = Field -10000 where Account id=A;
update Table name set Field = Field +10000 where Account id=B;
The above two statements must succeed or fail at the same time , One success and one failure are not allowed
To ensure that the above statements succeed or fail at the same time , Must use database " Transaction mechanism "
Only DML Statement to support transactions
DML Data operation language , Manipulate the data in the table , Connected to business (insert/delete/update);
Things exist to ensure data integrity and security ;
Suppose all businesses can use one DML No transaction mechanism is required for statement completion ;
How things work
Suppose one thing , You need to execute a insert, One more thing update, Finally, execute delete
Turn on the transaction mechanism ( Start )
perform insert sentence —> After successful execution , The execution is recorded in the operation history of the database , Data is not saved to the file , Will not really save to the hard disk ;
perform update sentence –>…;
perform delete sentence —>…;
Commit transaction commit Or roll back the transaction rollback( One of the two , Everything will end )
The four characteristics of affairs ACID
A: Atomicity : The smallest unit of things , Can not be further divided ;
C: Uniformity : Transactions must guarantee multiple DML Statements succeed or fail at the same time ;
I: Isolation, : Business A And business B Isolation between ;
D: persistence : The final data must be persisted to the hard disk file , It's the end of the business ;
The isolation of things
The isolation of things can be divided into 4 individual :
| First level | Read uncommitted (read uncommitted) | The other party's affairs have not been submitted , The current transaction can read the data not submitted by the other party ; There is dirty reading (Dirty Read) The phenomenon : Indicates that dirty data has been read ( Unstable data ) |
|---|---|---|
| The second level | Read submitted (read committed) | You can only read the data after the other party's transaction is committed , It can't be read repeatedly , Solve the dirty reading phenomenon ; |
| The third level | Repeatable (repeatable read) | Solved the unrepeatable read problem , The data read is fantasy ; |
| Level 4 | serialize / Serialization | All problems solved , Low efficiency , Transaction queuing is required ; |
Oracle The default isolation level of the database is : Read submitted ;
MySQL The default isolation level of the database is : Repeatable ;
// Set the isolation level of the transaction
set global transaction isolation level read uncommitted;// Read uncommitted
set global transaction isolation level read committed;// Read submitted
set global transaction isolation level repeatable read;// Repeatable
set global transaction isolation level serializable;// Serialization or serialization
// View transaction isolation level
select @@global.tx_isolation;
Automatic submission
MySQL Transactions are automatically committed by default ( Execute any one DML Statement is submitted once )
Turn off auto commit and turn on transactions :start transaction;
Save it :savepoint Custom location name ;
Rollback to the specified location :rollback Save it ;
The flow of a transaction
//1. Log in to the database ;
//2. Open database ;
//3. Set the transaction isolation level ;
set global transaction isolation level Level type ;
//4. Query transaction level
select @@global.tx_isolation;
//5. Turn off auto submit
start transaction;
//6.DML Statement operation
//7.rollback Rollback or commit Submit
MySQL Remote login
command :mysql -hhost -uusername -ppassword
host: Remote host address
username: user name
password: password
边栏推荐
- 11. Multithreading
- Machine learning algorithm for large factory interview (5) recommendation system algorithm
- Using dynamic programming to solve the longest growing subsequence problem
- BST树
- The user logs in continuously (interruption is allowed) to query SQL
- NFT digital collection system development: Shenzhen Evening News "good times travel" digital collection online seconds chime
- 3. DQL (data query statement)
- Image fuzzy processing batch production fuzzy data set
- Quartz2.2 simple scheduling job
- UE4解决WebBrowser无法播放H.264的问题
猜你喜欢

NFT digital collection development: what are the possible application scenarios of digital collections in the future?

Develop necessary idea use

八、集合框架和泛型

UE4.24版本VR项目打包后,未出现手柄控制器

Development of digital collection system: enterprise layout meta universe digital collection

九、实用类
![[untitled]](/img/c6/735dec4022d7fed8a62b5df45df17b.png)
[untitled]

Installation and process creation of activiti app used by activiti workflow

高德定位---权限弹框不出现的问题

数仓4.0笔记——用户行为数据采集三
随机推荐
Development of digital collection system / introduction of digital collection scheme
shell取某一时间范围内月份
New BPMN file used by activiti workflow
MySQL数据库
Websocket long connection
1.认识数据库
查看真机APP里面沙盒文件
One of scala variables and data types
Ten year structure five year life-01 at the beginning of graduation
数仓4.0笔记——用户行为数据采集一
Activiti7 Quick Start experience sharing
数仓4.0笔记——用户行为数据采集二
Project instances used by activiti workflow
MySQL modify function permission is not effective
MySQL invalid conn troubleshooting
SQL realizes the user statistics of continuous login for more than 7 days
分治与递归(练习题)
Entrepôt de données 4.0 Notes - acquisition de données sur le comportement de l'utilisateur II
NFT trading platform digital collection system | development and customization
Data warehouse 4.0 notes - user behavior data generation