当前位置:网站首页>Deeply understand MySQL transaction isolation level and locking mechanism
Deeply understand MySQL transaction isolation level and locking mechanism
2022-07-21 07:05:00 【Palpitation】
** In depth understanding of Mysql Transaction isolation level and locking mechanism **
** summary **
Our database usually executes multiple transactions concurrently , Multiple transactions may add, delete, modify and query the same batch of data concurrently , Probably It will lead to what we call dirty writing 、 Dirty reading 、 It can't be read repeatedly 、 Read these questions . The essence of these problems is the multi transaction concurrency of database , In order to solve the problem of multi transaction concurrency , Transaction isolation mechanism is designed for database 、 Locking machine system 、MVCC Multi version concurrency control isolation mechanism , Use a set of mechanisms to solve the problem of multi transaction concurrency . Next , We will explain these machines in depth system , Let's thoroughly understand the execution principle inside the database .
** Affairs and ACID attribute ** The business is made up of a group of SQL A logical processing unit made up of statements , The transaction has the following 4 Attributes , Usually referred to as transaction ACID attribute . Atomicity (Atomicity) : A transaction is an atomic unit of operation , Its modification of data , Or do it all , Or none of them . Uniformity (Consistent) : At the beginning and end of the transaction , Data must be consistent . This means that all relevant data specifications Must be applied to the modification of the transaction , To maintain the integrity of the data . Isolation, (Isolation) : The database system provides a certain isolation mechanism , Ensure that transactions are not affected by external concurrent operations “ single state ” Environmental execution . This means that the intermediate state in the transaction process is not visible to the outside , vice versa . persistence (Durable) : After the transaction completes , Its modification of data is permanent , Even if there is a system failure, it can keep .
** Problems caused by concurrent transaction processing **
** Update missing (Lost Update) Or dirty writing **
When two or more transactions select the same row , When the row is then updated based on the originally selected value , Because each transaction does not know the existence of other transactions stay , There will be lost updates – The last update covers the updates made by other firms .
** Dirty reading (Dirty Reads)**

1 ‐‐ Build table SQL
2 CREATE TABLE `mylock` (
3 `id` INT (11) NOT NULL AUTO_INCREMENT,
4 `NAME` VARCHAR (20) DEFAULT NULL,
5 PRIMARY KEY (`id`)
6 ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
7
8 ‐‐ insert data
9 INSERT INTO`test`.`mylock` (`id`, `NAME`) VALUES ('1', 'a');
10 INSERT INTO`test`.`mylock` (`id`, `NAME`) VALUES ('2', 'b');
11 INSERT INTO`test`.`mylock` (`id`, `NAME`) VALUES ('3', 'c');
12 INSERT INTO`test`.`mylock` (`id`, `NAME`) VALUES ('4', 'd');






2) On the client side A Before the transaction is committed , Open another client B, Update table account:
3) At this time , client B The business of has not been submitted , client A Can't find B Updated data , Solved the problem of dirty reading :

5) client A Execute the same query as in the previous step , result Inconsistent with the previous step , That is to say, there is the problem of non repetition

2) On the client side A Before the transaction is committed , Open another client B, Update table account And submit






show status like 'innodb_row_lock%';

边栏推荐
- JVM 基础
- Iron nails pierce the head, yogurt bottles "bite" the tongue... Guangdong fire: Summer children's safety can not be ignored
- 体系对于哲学的重要性-黑格尔
- 打造数据驱动型组织,成长型企业最需要什么?
- Postgresql中函数详解看一篇就够了——常用函数以及使用方法
- Wallys/DR882/QCA9882/ AC/AN MiniPCIE/2 × 2.4GHz 2x5GHz MT7915 MT7975
- CV (3)- Loss Functions and Optimization
- Wallys/DR882/QCA9882/ AC/AN MiniPCIE/2×2.4GHz 2x5GHz MT7915 MT7975
- MoCo V3:视觉自监督迎来Transformer
- MySQL 啥时候用表锁,啥时候用行锁?
猜你喜欢
打造数据驱动型组织,成长型企业最需要什么?
Web3 社交赛道的新变化:向族群化、场景化转变
《运营商数据存力指标》发布,透露了哪些重要趋势?
DDR 6 memory has been put into research and development
Communication tutorial | USB, HDMI, DP interface and speed
【Flutter -- 顶部导航栏】TabBarView 的基本使用
Windows Server 2022获7月非安全更新:修复因Defender导致的卡死问题
【Flutter -- 基础组件】按钮组件 - ElevatedButton、TextButton、OutlinedButton、IconButton
NC | chenghuan Institute zhuyongguan team - potential of marine plastic circles in the process of nitrogen geochemical cycle
Few-shot Video-to-Video(NeurIPS 2019)视频生成论文解读
随机推荐
Communication tutorial | USB, HDMI, DP interface and speed
Few-shot Video-to-Video(NeurIPS 2019)视频生成论文解读
(Note)神经网络中的特征融合方式(add/concate)
ECCV 2022 | 旷视提出半监督目标检测模型Dense Teacher,取得SOTA性能
【Flutter -- 布局】Container 的基础使用
Iron nails pierce the head, yogurt bottles "bite" the tongue... Guangdong fire: Summer children's safety can not be ignored
Wallys/3×3/2×2 MIMO/ 802.11ac/ Mini PCIe /2,4GHz / 5GHz QCA 9880
promise 基础使用
6-10漏洞利用-Smtp实验环境搭建
[shutter -- layout] basic use of container
CV (3)- Loss Functions and Optimization
setTimeout传参[通俗易懂]
【Flutter -- 顶部导航栏】TabBarView 的基本使用
ARM 如果通过笔记本机上外网?
(note) CIE chromaticity diagram
编程必备,程序员应该都知道的7款文本编辑器
[shutter -- basic component] text component text & TextStyle & textspan
[shutter -- top navigation bar] basic use of tabbarview
PostgreSQL是什么?StackOverflow上开发者最爱和最想要的关系型数据库
General GUI large disk based on MCU