当前位置:网站首页>Linux server development, MySQL transaction principle analysis
Linux server development, MySQL transaction principle analysis
2022-07-07 07:55:00 【Tuen Mun pheasant calls me chicken】
Recommend a free open course of zero sound College , Personally, I think the teacher spoke well , Share with you :Linux,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK, Streaming media ,CDN,P2P,K8S,Docker,TCP/IP, coroutines ,DPDK Etc , Learn now
1. What is the business
A transaction is going from one consistency state to another consistency state .
sentence
- START TRANSACTION | BEGIN
- COMMIT
- ROLLBACK
- SAVEPOINT identifier
- ROLLBACK TO SAVEPOIN
2.ACID characteristic
Atomicity (A)
Commit transactions or do all , Either not .
Uniformity (C)
A transaction unit can only be visible by other transactions after committing transactions .
Isolation, (I)
Multiple connections process data at the same time , Don't affect each other . To improve performance , Through granularity lock , Set different isolation levels .
persistence (D)
DML Operations are persisted , Even if it goes down , Data can be retrieved according to the log .
3. Isolation level
READ UNCOMMITTED
Read uncommitted , Reads at this level are unlocked , Write and lock it , Write locks release locks after a transaction is committed or rolled back .
READ COMMITTED
Read submitted RC, Support... From this level MVCC, That is, to provide consistent, unlocked reads ; At this time, read the historical snapshot data ; Read the latest data of the historical version under this isolation level , So read the submitted data .
REPEATABLE READ
Repeatable RR, Support MVCC, At this time, the read operation reads the version data at the beginning of the transaction .
SERIALIZABLE
Serialization , Support MVCC, The highest level of isolation .
command :
– Set level isolation
SET GLOBAL |SESSION TRANSACTION ISOLATION LEVE REPEATABLE READ;
SET @@tx_isolation=‘REPEATABLE READ’;
SET @@global.tx_isolaction =‘REPEATABLE READ’;
– View global level isolation
SELECT @@global.tx_isolation;
– View the current level of isolation
SELECT @@session.tx_isolation;
SELECT @@tx_isolation;
– Manually add... To the reading S Read the lock
SELECT … LOCK IN SHARE MODE;
– Manually add... To the reading X Write lock
SELECT …FOR UPDATE;
– View the current lock information
SELECT &FROM information_schema.innodb_locks;
S Shared lock :
Lock added by transaction read operation , Lock every line , Only serialization will add S lock .
x Exclusive lock :
The transaction deletes or updates the lock added , Lock on a line . This lock is added to all four isolation levels .
IS Intention sharing lock :
Intention lock is to tell other things , This form is in use . Function exclusion table lock reading . Insert with IS, add X. Use exclusive locks indirectly .
IX Intention exclusive lock :


Intention locks and read-write locks at the full table level will conflict , Intention will only conflict with row lock , Row lock conflicts with row lock .
GAP LOCK Clearance lock and NEXT-KEY Lock these two locks only in READ REPEATE Exists under level . The clearance lock locks a range , But not the record itself , Fully open section NEXT-KEY It's a record lock + Clearance lock , Lock a range and record itself , Left open right closed interval . These two locks often cause deadlocks .
INSERT INTENTION LOCK, For example 1,7 Row insertion , If there is an intention to insert a lock, it can be inserted simultaneously 3,4. Improve the concurrency performance of the insertion gap .
AUTO INCR-LOCK Low probability of self incrementing lock B+ The split of the tree , Improved self growth value insertion performance .

Dirty reading
Business A Read another uncommitted transaction .
It can't be read repeatedly
Business A You can read about affairs B Data submitted , It usually happens in a transaction that reads data different from the transaction .
Fantasy reading
Read the same range of data twice , Result set ( More or different data ) Dissimilarity . Non repeatable reading refers to row data , Unreal reading refers to the scope .
Locking before a transaction starts is a persistent lock , The lock is released only when the transaction is committed or rolled back .
Lost update
Both transactions are written , It is divided into commit overrides and rollback overrides . Rollback overwrite has been rejected by the database .
Look at deadlocks
– Turn on standard monitoring
- CREATE TABLE innodb_monitor(a INT) ENGINE=INNODB;
– Turn off standard monitoring - DROP TABLE innodb_monitorl
– Turn on the lock monitor - CREATE TABLE innodb_lock_monitor ( INT ) ENGINE=INNOB;
– Turn off lock monitoring - DROP TABLE innodb_lock_monitor
– Turn on standard monitoring
- set GLOBAL innodb_status_output_ON;
– Turn off standard monitoring - set GLOBAL innodb_status_status_output=OFF;
– Turn on the lock monitor - set GLOBAL innodb_status_outpus_locks=ON;
– Turn off lock monitoring - set GLOBAL innodb_status_output_locks=OFF;
– Record deadlock information in the error log - set GLOBAL innodb_print_all_deadlocks=ON;
边栏推荐
- [guess-ctf2019] fake compressed packets
- [webrtc] m98 Screen and Window Collection
- [webrtc] M98 screen and window acquisition
- Jenkins remote build project timeout problem
- [2022 ciscn] replay of preliminary web topics
- Six methods of flattening arrays with JS
- 2022焊工(初级)判断题及在线模拟考试
- LeetCode 90:子集 II
- A bit of knowledge - about Apple Certified MFI
- [VHDL parallel statement execution]
猜你喜欢

Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!
![[Stanford Jiwang cs144 project] lab3: tcpsender](/img/82/5f99296764937e7d119b8ab22828fd.png)
[Stanford Jiwang cs144 project] lab3: tcpsender

【数学笔记】弧度
![[SUCTF 2019]Game](/img/9c/362117a4bf3a1435ececa288112dfc.png)
[SUCTF 2019]Game

微信小程序基本组件使用介绍

Why should we understand the trend of spot gold?

即刻报名|飞桨黑客马拉松第三期等你挑战

Problem solving: unable to connect to redis

2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
![[UTCTF2020]file header](/img/e3/818e2d531a06ab90de189055f634ad.png)
[UTCTF2020]file header
随机推荐
Cnopendata geographical distribution data of religious places in China
【obs】win-capture需要winrt
通信设备商,到底有哪些岗位?
[Stanford Jiwang cs144 project] lab3: tcpsender
Explore Cassandra's decentralized distributed architecture
The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
Thinkcmf6.0安装教程
buuctf misc USB
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
探索干货篇!Apifox 建设思路
vus.SSR在asynData函数中请求数据的注意事项
C语言队列
Rust Versus Go(哪种是我的首选语言?)
[unity] several ideas about circular motion of objects
C language flight booking system
Asemi rectifier bridge rs210 parameters, rs210 specifications, rs210 package
Tianqing sends instructions to bypass the secondary verification
[UVM foundation] what is transaction
[2022 ciscn] replay of preliminary web topics
2022制冷与空调设备运行操作复训题库及答案