当前位置:网站首页>MySQL 45 lecture learning notes (II) execution of SQL update statements
MySQL 45 lecture learning notes (II) execution of SQL update statements
2022-06-22 03:39:00 【Comtom】
One . Log module :redo log
Existing problems :
- Every update operation needs to be written to disk , Then the disk finds the corresponding record , Then update , The whole process IO cost , High cost of discovery .
Solution :
WAL technology ,Write-Ahead Logging
- Write the log , Write the disk again ---- And Redis On the contrary
Two .WAL technology
- When a record needs to be updated ,InnoDB The engine will write the record first redo log And then update the memory , At this time, the update is completed .
- InnoDB The engine will... At the right time , Update this operation record to disk , This update usually occurs when the system is idle .
3、 ... and . redo log
InnoDB Of red log Is constant , Can be configured as a set of 4 File , The size of each file is 1GB

InnoDB Can guarantee even if The database is restarted abnormally , Before No records submitted will be lost , This ability is called crash-safe.
Four . Log module :binlog
- Server Layer log -binlog( Archive log )
- Engine layer , Responsible for storing the corresponding specific matters ,innoDB journal -redo log
Differences between the two :
- redo log yes InnoDb Engine specific ;binlog yes MySQL Of server Layer , All engines can use .
- redo log It's a physical log , The record is “ What changes have been made on a data page ”,binlog It's a logical log , Record execution statement
- redo log It's circular , The space will be used up ;binlog Yes, it can be added , finger binlog The file will always be appended , The previous log will not be overwritten .
5、 ... and . perform update The internal flow of the statement
- The actuator looks for the engine first ID=2 This business .ID It's the primary key , The engine uses a tree search directly to find this line , If ID=2 The data page where this line is located is already in memory , Directly back to the actuator , Otherwise, read from the disk into the memory and return .
- The actuator gets the engine row data , Add the values of a , Then call the engine interface to write
- The engine updates this new row of data into memory , At the same time, the update operation is recorded to redo log in , here redo log be in prepare state , Then tell the actuator to complete , You can commit a transaction .
- The actuator generates the binlog, And put binlog Write to disk .
- The executor calls the engine's commit transaction interface , The engine just wrote redo log Change to submit (commit) state , Update complete .

6、 ... and . Two-phase commit
- Why do I have to submit in two phases ?
- Make the logic of the two logs consistent
How to restore the database to any second in half a month
Solution :
- binlog Will record all logical operations , And adopt " Additional writing " In the form of
- The backup system can save all the data in the last half month binlog, At the same time, the system will backup the whole database regularly
- This periodicity can depend on the importance of the system , It can be backed up once a day , It can also be backed up once a week .
Restore the scene : One day at two o'clock in the afternoon, I found that there was a mistake to delete the table at twelve o'clock in the afternoon
- Find the last full backup , Restore to temporary Library ;
- From the point in time of the backup , Will back up binlog Take them out one by one , Put it back to the time before the table was deleted by mistake at noon .
- Table data is fetched from the temporary database , Restore to online library as needed .
The disadvantage of not doing two submissions :
First write redo log Post write binlog
- hypothesis redo log finish writing sth. ,binlog Before writing ,musql collapse
- redo log After writing , System crash , So you can recover the data
- binlog I didn't finish writing crash 了 , Now binlog No record of this statement .
- But by binlog Synchronized slave libraries will result in missing commands from the slave libraries .
First write binlog To write redo log
- binlog After writing crash live , however redo log Not yet , The transaction is invalid at this time
- however binlog The log has been recorded
- Then through the binlog Synchronous slave libraries will cause the slave libraries to increase the execution of this command .
- redo log Used to guarantee crash-safe Ability
- innodb_flush_log_at_trx_commit by 1 Ensure that each transaction is redo_log All persist directly to disk ,mysql No data loss after restart .
- sync_binlog This parameter is set to 1 When , For each transaction binlog Will be persisted to the disk mysql After abnormal restart binlog No loss .
边栏推荐
- 华硕重装系统键盘灯失效 =>重装ATK驱动
- float浮点数理解
- 策略模式
- Are you a technology manager or a project manager?
- 达梦数据库客户端屏蔽sql关键字
- When 618 attacks, how to choose between Beibei X3 and Jimi h3s? Take you all-round in-depth analysis
- 分析Iceberg合并任务解决数据冲突
- 倍福嵌入式控制器PLC各型号介绍
- Snappy format parsing
- Nepal graph learning Chapter 2_ A bug before version v2.6.1 caused OOM
猜你喜欢
随机推荐
How to randomly assign 1000 to 10 numbers
ORA-32700: error occurred in DIAG Group Service
1299. 将每个元素替换为右侧最大元素
Template as interface
Project management software development project management
LOCAL=NO
我们如何解决了RealSense偏色问题?
mysql 查询表的字段的属性、注释、字段信息
vim常用命令
动态规划-使用最小花费爬楼梯为例
微信小程序聊天 表情
魔法方法《六》__enter__和__exit__
内网穿透
作为接口的模板
倍福CX9020(WINCE 7)控制器使用方法和操作
Float floating point number understanding
Implementation of synchronization and atomic operation by mutex mutex in golang concurrent programming
Talk about the Flink waterline
Nebula Graph学习篇2_版本v2.6.1之前的bug导致OOM
76. minimum covering substring sliding window method








