当前位置:网站首页>MySQL transaction
MySQL transaction
2022-06-21 15:28:00 【gaoZhuanMing】
1. The nature of the transaction
- Atomicity (Atomicity): All operations in a transaction , Or it's all done , Or not at all , It doesn't end in the middle .
- Uniformity (Consistency): Before and after transaction start , The integrity of the data is not compromised , That is to say, it completely conforms to all the preset rules .
- Isolation, (Isolation): Prevent data inconsistency caused by cross execution of multiple concurrent transactions .
- persistence (Durability): When the business is over , Changes to data are permanent , Even if the system fails, it will not be lost .
2. The transaction operations
Automatically submit by default : Each statement is a transaction .
# Turn off auto submit
SET AUTOCOMMIT=0;
# perhaps , Explicitly starts a transaction
BEGIN;
# Submit
COMMIT;
# Roll back
ROLLBACK;
# Declare a hold point
SAVEPOINT savepoint_name;
# Rollback to the specified retention point
ROLLBACK TO savepoint_name;
# Release the hold :COMMIT, ROLLBACK Then it will be released automatically
RELEASE SAVEPOINT savepoint_name;
3. Isolation,
Problems with concurrent transactions :
- Dirty reading : Business tx1 Read the transaction tx2 Updated but not yet submitted data , Then if tx2 Roll back , be tx1 What you read is temporarily invalid content .
- It can't be read repeatedly : Business tx1 Read a field , Then transaction tx2 Updated the field , Then business tx1 This field is read again , Business tx1 The contents read before and after are inconsistent .
- Fantasy reading : Business tx1 First, query a table , Then transaction tx2 Some new rows have been inserted into the table , If the transaction tx1 Read the table again , You will find new lines .
Isolation level :
- READ UNCOMMITTED: Dirty reading will occur 、 It can't be read repeatedly 、 Fantasy reading .
- READ COMMITTED: Avoid dirty reading , But it can not solve the problem of unrepeatable reading and unreal reading .
- REPEATABLE READ( Default ): Avoid dirty reading 、 It can't be read repeatedly , But I can't understand the unreal reading .
- SERIALIZABLE: Can solve all the problems .
# View the current isolation level
SELECT @@tx_isolation;
# Set the isolation level of the current session
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
边栏推荐
- Summary of the most basic methods of numpy
- 通过编译内核的方式增加系统调用
- Teach you to stop visiting a website
- Machine learning model training template
- Somme factorielle
- 进程之间使用共享内存通信
- Fundamentals of C language 13: file input / output
- Not only products, FAW Toyota can give you "all-round" peace of mind
- 利用并查集求最小生成树
- What is a naked cat
猜你喜欢

Fundamentals of C language 13: file input / output

AAAI 2022 | sasa: rethinking point cloud sampling in 3D object detection

Operator Tour (I)

Best practice | how to use Tencent cloud micro build to develop enterprise portal applications from 0 to 1

C language to achieve three chess (detailed explanation)

Analysis report on competition trend and development scale of China's heavy packaging industry 2022-2028 Edition

Algorithm question: interview question 32 - I. print binary tree from top to bottom (title + idea + code + comments) sequence traversal time and space 1ms to beat 97.84% of users once AC

Learn upward management and four questioning skills to get twice the result with half the effort

H2O brings AI master NLP technology to enterprises

Promotion guide for large enterprises: material preparation, PPT writing and on-site defense
随机推荐
Color segmentation based on RGB difference method
Integration of sparkstreaming and sparksql
Rk3399 platform development series explanation (network debugging) 7.33 network performance optimization
C language pointer
5700s layer 2 interface and layer 3 interface switching
Build an efficient and scalable result cache
Build an efficient and scalable result cache
JS interview questions: variable promotion function promotion, scope chain error prone questions
PCA dimension reduction application of OpenCV (I)
So many statistical charts? This visualizer is great~~
阶乘求和
Phantom star VR product details 31: escape from the secret room
A horse stopped a pawn
Redis5.0 installation and production startup steps
JS written test question: this
C language function fgets
Merge two ordered linked lists
Mysql5.7 setup password and remote connection
Idea restart
Non local network: early human attempts to tame transformer in CV | CVPR 2018