当前位置:网站首页>Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
2022-07-31 02:50:00 【孔汤姆】
一.binlog的写入机制
执行逻辑:
- 事务执行过程中,先把日志写到binlog cache,
- 事务提交的时候再把binlog cache写到binlog文件中
binlog cache
- 系统binlog cache分配了一片内存,每个线程一个
- 参数binlog_cache_size用于控制单个线程内binlog cache所占内存的大小
- 如果超过了这个参数规定的大小,就要暂存到磁盘
事务提交时:
- 执行器把binlog cache里的完整事务写入binlog中,并清空binlog cache
二.Redo log的写入机制
redo log的三种状态:
- 存在redo log buffer中,物理上是在MySQL进程内存中
- 写在磁盘(write),但没有持久化(fsync),物理上是在文件系统的page cache里面
- 持久化到磁盘,对应的是hard disk
存在问题:
日志写到redo log buffer 是很快的,write到page cache也差不多,但是持久化到磁盘的速度很慢
innodb_flush_log_at_trx_commit 参数
0 | 表示每次提交事务都把redo log留在redo log buffer中 |
1 | 表示每次事务提交时都将redo log 直接持久化到磁盘 |
2 | 表示每次事务提交时都只把redo log写到page cache |
- InnoDB有一个后台 线程,每隔1秒,就会把redo log buffer中的日志,调用write写到文件系统的page cache,然后调fsync 持久化到磁盘
- 事务执行中间过程的redo log也是直接写在redo log buffer中的
- 也可能被后台线程一起持久化到磁盘中。
- 一个没有提交的事务的redo log可能已经持久化到磁盘。
三.没提交的redo log写入磁盘的两个场景:
- redo log buffer占用的空间即将达到innodb_log_buffer_size一半的时候,后台线程会主动写盘
- 并行事务提交的时候,顺带将这个事务的redo log buffer 持久化到磁盘
两阶段提交:
时序上redo log先prepare再写binlog最后再把redo log commit
组提交(group commit)机制
边栏推荐
- To write good test cases, you must first learn test design
- 8、统一处理异常(控制器通知@ControllerAdvice全局配置类、@ExceptionHandler统一处理异常)
- Introduction to flask series 】 【 flask - using SQLAlchemy
- CorelDRAW2022 streamlined Asia Pacific new features in detail
- Unity3D Button mouse hover enter and mouse hover exit button events
- Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
- StringJoiner in detail
- 图像处理技术的心酸史
- 品牌广告投放平台的中台化应用与实践
- SQL 面试用题(重点)
猜你喜欢
SQL注入 Less46(order by后的注入+rand()布尔盲注)
【Bank Series Phase 1】People's Bank of China
关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
Intel's software and hardware optimization empowers Neusoft to accelerate the arrival of the era of smart medical care
The Sad History of Image Processing Technology
8、统一处理异常(控制器通知@ControllerAdvice全局配置类、@ExceptionHandler统一处理异常)
【C语言】三子棋(经典解法+一览图)
MPPT太阳能充放电控制器数据采集-通过网关采集电池电压容量电量SOC,wifi传输
General introduction to the Unity interface
StringJoiner in detail
随机推荐
What is a distributed lock?Three ways of implementing distributed lock
加密公司向盗窃的黑客提供报价:保留一点,把剩下的归还
print task sorting js od huawei
YOLOV5 study notes (2) - environment installation + operation + training
汉源高科8路HDMI综合多业务高清视频光端机8路HDMI视频+8路双向音频+8路485数据+8路E1+32路电话+4路千兆物理隔离网络
StringJoiner in detail
The application of AI in the whole process of medical imaging equipment
CorelDRAW2022 streamlined Asia Pacific new features in detail
The principle of complete replication of virtual machines (cloud computing)
7、私信列表
冒泡排序、选择排序、直接插入排序、二分法查找
General introduction to the Unity interface
There is a problem with the multiplayer-hlap package and the solution cannot be upgraded
Word/Excel fixed table size, when filling in the content, the table does not change with the cell content
Maximum area of solar panel od js
10、Redis实现点赞(Set)和获取总点赞数
Basic learning about Redis related content
Huawei od dice js
直播预告 | KDD2022博士论文奖冠亚军对话
Installation, start and stop of redis7 under Linux