当前位置:网站首页>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
边栏推荐
- Customized development of ant chain NFT digital collection DAPP mall system
- Typescript common types
- Chinese interpretation of notepad++ background color adjustment options
- Installation and process creation of activiti app used by activiti workflow
- Entrepôt de données 4.0 Notes - acquisition de données commerciales
- 数仓4.0笔记——业务数据采集——Sqoop
- [untitled]
- 數倉4.0筆記——業務數據采集
- Data warehouse 4.0 notes - business data collection
- Phxpaxos installation and compilation process
猜你喜欢

UE4解决WebBrowser无法播放H.264的问题

NFT digital collection development /dapp development

Image fuzzy processing batch production fuzzy data set

2、MySQL数据管理--DML(添加、修改、删除数据)

ninja介绍及使用

ninja启动过程
![[untitled]](/img/c6/735dec4022d7fed8a62b5df45df17b.png)
[untitled]

Machine learning algorithm for large factory interview (5) recommendation system algorithm

Internet communication

UItextview的textViewDidChange的使用技巧
随机推荐
Installation and process creation of activiti app used by activiti workflow
NFT digital collection platform development and construction, source code development digital collection
数仓4.0笔记——用户行为数据采集四
MySQL modify function permission is not effective
Mysql database
11. Multithreading
[untitled]
Ten year structure five year life-01 at the beginning of graduation
Development of digital collection system: enterprise layout meta universe digital collection
Shell takes the month within a certain time range
Development of digital collection system: Baidu AI pays tribute to Air China
规范数据库设计
循环队列
Kubesphere ha install (II)
链栈
[pyautogui learning] screen coordinates and mouse scrolling
APP自动化测试工具-appium的安装及使用
11、多线程
Development of digital collection system: what are the main features of NFT?
Accumulate SQL by date