当前位置:网站首页>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.
边栏推荐
- Azure developer news flash list of events of developers in June
- What should academic presentation /ppt do?
- Raki's notes on reading paper: named entity recognition as dependency parsing
- Comparable和Comparator的区别
- Use of Arthas
- How can redis+aop customize annotations to achieve flow restriction
- Cross domain, CORS, jsonp
- Tri rapide, index groupé, recherche de la plus grande valeur K dans les données
- Customize the buttons of jvxetable and the usage of $set under notes
- Global and Chinese markets for wireless security in LTE networks 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

CMake教程系列-02-使用cmake代碼生成二進制

Call collections Sort() method, compare two person objects (by age ratio first, and by name ratio for the same age), and pass lambda expression as a parameter.

IDEA 远程调试 Remote JVM Debug

How to use vant to realize data paging and drop-down loading

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

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

Série de tutoriels cmake - 02 - génération de binaires à l'aide du Code cmake

Federal learning: dividing non IID samples by Dirichlet distribution

Pytoch learning (II)

自定义JvxeTable的按钮及备注下$set的用法
随机推荐
Which is a good foreign exchange trading platform? Is it safe to have regulated funds?
JvxeTable子表记录加载完毕事件
LeetCode 3. Longest substring without duplicate characters
IBM WebSphere channel connectivity setup and testing
【微信小程序】条件渲染 列表渲染 原来这样用?
 与空格的区别
Unity TimeLine 数据绑定
IDEA 远程调试 Remote JVM Debug
CMake教程系列-05-选项及变量
What is the metauniverse: where are we, where are we going
List of development tools
福利抽奖 | 开源企业级监控Zabbix6.0都有哪些亮点
HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化
微信小程序页面跳转以及参数传递
Heavy attack -- ue5's open source digital twin solution
Unity3d ugui force refresh of layout components
How to prevent duplicate submission under concurrent requests
PHP two-dimensional array randomly fetches a random or fixed number of one-dimensional arrays
2.8 【 weight of complete binary tree 】
C console format code