🔄Update: MySQL

This commit is contained in:
2025-09-26 14:55:31 +08:00
parent c0aab77773
commit e55aff895e
3 changed files with 83 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
# 隔离级别
- 读未提交
- 未提交事务的修改可见
- 读提交
- 提交事务的修改可见
- 可重复读
- 事务启动时看到数据保持一致
- 串行化
- 阻塞执行
**用于解决的问题**
- 脏读
- 读到未提交事务修改的数据
- 读提交解决此问题
- 不可重复读
- 在事务中多次读取数据不一致
- 可重复读解决此问题
- 幻读
- 多次查询符合某个条件的记录数不一致
- 串行化解决此问题
**具体实现**
- 读未提交
- 每次读取最新数据
- 读提交
- 每个语句执行前 `Read View`
- 可重复读
- 事务开始时 `Read View`
- 串行化
- 加读写锁
**Read View**
![Read View](https://cdn.xiaolincoding.com/gh/xiaolincoder/ImageHost4@main/mysql/%E4%BA%8B%E5%8A%A1%E9%9A%94%E7%A6%BB/readview%E7%BB%93%E6%9E%84.drawio.png)
事务划分——
- 已提交事务
- `trx_id < min_trx_id`
- 活跃事务
- `min_trx_id <= trx_id < max_trx_id`
- 未开始事务
- `trx_id >= max_trx_id`
+20
View File
@@ -0,0 +1,20 @@
# 锁
**按加锁的范围分类**
- 全局锁
- 表级锁
- 行级锁
## 全局锁
- 全库逻辑备份
## 表级锁
1. 表锁
2. 元数据锁
3. 意向锁
4. Auto-INC 锁
### 行级锁
+18
View File
@@ -0,0 +1,18 @@
# 日志
- `undo log`
- 事务回滚
- MVCC
- `redo log`
- 持久性保证(掉电恢复)
- `binlog`
- 数据备份
- 主从复制
![redo log](https://cdn.xiaolincoding.com/gh/xiaolincoder/mysql/how_update/wal.png?image_process=watermark,text_5YWs5LyX5Y-377ya5bCP5p6XY29kaW5n,type_ZnpsdHpoaw,x_10,y_10,g_se,size_20,color_0000CD,t_70,fill_0)
**两阶段提交**
- redo log
- binlog
![两阶段提交](https://cdn.xiaolincoding.com/gh/xiaolincoder/mysql/how_update/%E4%B8%A4%E9%98%B6%E6%AE%B5%E6%8F%90%E4%BA%A4.drawio.png?image_process=watermark,text_5YWs5LyX5Y-377ya5bCP5p6XY29kaW5n,type_ZnpsdHpoaw,x_10,y_10,g_se,size_20,color_0000CD,t_70,fill_0)