当前位置:网站首页>Mysqldump principle
Mysqldump principle
2022-06-30 02:58:00 【PentaQwQ】
Reference resources
mysqldump Common parameter usage
mysqldump Analysis of the principle of consistent hot standby
Common parameters
-A/–all-databases Back up all databases
-B/–databases Backing up multiple libraries
mysqldump -uxx -pxxx -B Library name 1 Library name 2 >xxx.sql–single-transaction Used only for innodb engine , It is used to ensure the consistency of data backup
–master-data=1/2
This option will binlog Write the location and file name of to the output . This option requires RELOAD jurisdiction , And must be enabled binlog journal .
If the option value is 1, The location and file name are written to CHANGE MASTER Dump output in the form of statement , If you use this SQL Dump the master server to set up the slave server , Start from the correct location of the binary log of the primary server
If the option value is 2,CHANGE MASTER The statement is written as SQL notes–dump-slave=1/2 This parameter is used to back up data from the library , Set up a new slave library online
–no-data/-d Back up table structure only , Don't back up data
–complete-insert/-c Use the complete insert statement , It can improve the insertion efficiency
When this parameter is not used , Insert statement similar insert into values (?,?,?)
When using this parameter , Insert statement similar insert into (key1,key2) values (?,?)-t Export only insert sentence
–where=/w Export conditions , You can limit the range of data you want to export
–default-character-set Set character set
-F/–flush-logs Refresh 2 System log
–lock-all-tables/-x Submit a request to lock all tables in the database , To ensure data consistency . This is a global read lock , And turn it off automatically single-transaction and –lock-tables Options
Main operation
- Connect server
- Close all tables twice , Add a read lock when closing all tables for the second time
- Set transaction isolation level to repeatable read
- Get current binlog Location
- Unlock all tables
- The specified libraries and tables are dump
How it works
1. Connect server
Link to the server first , initialization session As well as some session Level parameters
2. Close all tables twice , The second time the meter is closed, a read lock is added
if ((opt_lock_all_tables || opt_master_data ||
(opt_single_transaction && flush_logs)) &&
do_flush_tables_read_lock(mysql))
goto err;
In the source code, you can see that there are only three cases in which the table closing operation will be performed
- adopt –lock-all-tables Option explicitly requires that all tables be locked
- adopt –master-data Option requirements dump The results include binlog Location
- adopt –single-transaction Specifies the consistent backup of a single transaction , At the same time through –flush-logs Refresh required log file
The only –single-transaction Option does not require locking , because –single-transaction The guaranteed consistent backup depends on a storage engine that supports transactions, such as Innodb. By creating snapshots and transactions id To filter out the data updates after the transaction . The advantage of this method is that it will not affect the normal operation of other transactions while performing a consistent backup . But you need to rely on a transactional storage engine .
Close all tables for the first time :
Close all open tables , Force all tables in use to close , And refresh all updated data to disk , It won't be locked at this time
Close all tables for the second time :
perform flush table operation , And add a global read lock .
The reason for closing all tables twice is to avoid a long transaction that causes the locking operation to be delayed , But it also blocks other client operations . For the first time flush The operation is also to minimize the second time flush Time to hold lock .
3. Set transaction isolation level to repeatable read , Start a transaction and create a snapshot
Repeatable read isolation level can avoid non repeatable read and unreal read .MVCC It will ensure that the data queried during the whole subsequent transaction is the same , Will not be affected by other matters .
4. Get current binlog Location
Only in the designated –master-data Option binlog Information about .
obtain binlog The way of information is mysqldump Execute one show master status Query for .
5. Unlock all tables
When specifying the –single-transaction When the command , At the official start dump Before ,mysqldump It will unlock all the tables that have been locked in the previous operation .
Because by MVCC Data consistency can be guaranteed , There is no need to lock these tables any more , Therefore, perform the unlocking operation , To avoid other transactions .
6. The specified libraries and tables are dump
dump Get the structure information of a table first , Get the creation statement of the table , Then get the actual data of each row in the table and generate the corresponding insert sentence .
First dump All tables in each specified database , Then if there is a view , The corresponding view will also be dump.
边栏推荐
- Recursion frog jumping steps problem
- Welfare lottery | what are the highlights of open source enterprise monitoring zabbix6.0
- LeetCode 3. 无重复字符的最长子串
- Cmake tutorial series -05- options and variables
- Federal learning: dividing non IID samples by Dirichlet distribution
- 可视化HTA窗体设计器-HtaMaker 界面介绍及使用方法,下载 | HTA VBS可视化脚本编写
- (图论) 连通分量(模板) + 强连通分量(模板)
- Unity timeline data binding
- Global and Chinese market of Kanban software 2022-2028: Research Report on technology, participants, trends, market size and share
- Jvxetable sub table record loading completion event
猜你喜欢

Summary of PHP test sites encountered in CTF questions (I)

HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化

Uniapp address translation latitude and longitude

Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery

约瑟夫环 数学解法

High paid programmers & interview questions series 63: talk about the differences between sleep (), yield (), join (), and wait ()

Use compose to realize the effect of selecting movie seats by panning tickets

Software testing skills, JMeter stress testing tutorial, transaction controller of logic controller (25)

What should academic presentation /ppt do?

oracle怎么设置密码复杂度及超时退出的功能
随机推荐
CMake教程系列-01-最小配置示例
2022 new test questions for safety management personnel of metal and nonmetal mines (small open pit quarries) and certificate examination for safety management personnel of metal and nonmetal mines (s
Jvxetable增加自定义按钮
Raki's notes on reading paper: named entity recognition as dependency parsing
Cross domain, CORS, jsonp
RAII内存管理
Distributed file system fastdfs
Xunwei enzhipu ITop - imx6 Development Platform
备忘一下es6的export/import和类继承的用法
Simulate activity startup mode in compose
Global and Chinese market of ERP software for garment and textile industries 2022-2028: Research Report on technology, participants, trends, market size and share
Study diary: February 15, 2022
Série de tutoriels cmake - 02 - génération de binaires à l'aide du Code cmake
Heavy attack -- ue5's open source digital twin solution
002 color classification
Global and Chinese markets for wireless security in LTE networks 2022-2028: Research Report on technology, participants, trends, market size and share
Multi card server usage
(图论) 连通分量(模板) + 强连通分量(模板)
Redis+AOP怎么自定义注解实现限流
New edition of diazotization process in 2022 and analysis of diazotization process