当前位置:网站首页>MySQL backup notes
MySQL backup notes
2022-07-04 03:11:00 【AbtYee】
MySQL Backup notes
Classification dimension of backup
- The state of the database at the time of backup
- Hot Backup( Hot standby ): Direct backup during normal operation
- Cold Backup( Cold standby ): Backup after complete stop
- Warm Backup( Warm preparation ): The database is read-only
- Format of backup file
- Logical backup : Output text or SQL sentence
- The physical backup ( Naked file ): Back up the underlying files of the database , As for the InnoDB Come on , It is commonly .idb Files and other metadata files
- Backup content
- Full backup : Back up full data
- Incremental backup : Backup data differences
- Log backup : Backup Binlog(Binlog Represents all data differences during this period , That is, the operation of data change )
Examples of tools
- mysqldump: Logic 、 heat 、 Full volume backup
- xtrabackup: Physics 、 heat 、 Total quantity + Incremental backup
Use OUTFILE Command backup
OUTFILE
- MySQL Native SQL Instructions
- The most original logical backup method
- The function and effect of backup depends on how to write SQL sentence
Usage mode
First find out MySQL Export path of
show variables like '%secure%';Use into outfile The command exports the query results to a file
select * into outfile '/var/lib/mysql-files/out_file_test' from table_xxx;
matters needing attention
- stay InnoDB Under transaction , You can achieve a consistent view , That is, under the isolation level of repeatable reading , After opening the transaction , because MVCC The existence of , At this time, each table is at the same time
- Modify the separator :fields terminated by
- Modify line breaks :lines terminated by
defects
- The output text is relatively simple
- It is difficult to restore , Now it is often used to simply export data
OUTFILE How to improve ?
- Send automatically SELECT sentence , No need to send manually
- Automatically start a transaction
- Output INSERT sentence , It can be directly used to restore
mysqldump
- Very common MySQL Logical backup tool
- MySQL Server Bring their own
- The output backup content is sql sentence , Balance reading and reduction
- sql Statements take up less space
principle
mysqldump Use the following statement to back up the data
SELECT SQL_NO_CACHE FROM `table_xxx`;SQL_NO_CACHE The queried data will not enter SQL cache
Usage method
Use the following statement to back up the data :
mysqldump -uroot -p111111 --databases d1 --single-transaction > xxx.sql;Directly execute the exported sql Files can be restored
source xxx.sql;
matters needing attention
- –single-transaction: stay RR Level (InnoDB)
- –lock-all-tables: Use FTWRL Lock all tables (MyISAM)
- –lock-tables: Use READ LOCAL Lock the table of the current library (MyISAM)
- –all-databases: Back up all databases
shortcoming
- Export logical data , Slow backups
- Restore needs to be performed sql, The speed is also slow
Incremental backup
mysqldump Incremental backup is not allowed , Because it is sent to every table in the Library select * sentence , So how to realize incremental backup ?
Ideas :
- binlog Faithfully recorded MySQL Data change
- mysqldump After full backup , It can be used binlog As an increment
- mysqldump Full backup , Switch to new binlog file
- When restoring from zero , Use full reduction +binlog Restore
step
One 、mysqldump Full volume backup
mysqldump Use the following statement to back up the data in full :
mysqldump -uroot -p111111 --database d1 --single-transaction --flush-logs --master-data=2 > xxx.sql–flush-logs: Switch after backup binlog file
–master-data=2: Record the binlog file name
Two 、binlog Incremental backup
When incremental backup is required , Switch binlog file
mysqladmin -uroot -p111111 flush-logsAdd all new binlog File backup
3、 ... and 、 Restore
First restore the old full backup
source xxx.sql;And then binlog Incremental restore to database
mysqlbinlog MySQL-bin.000002 ...( Multiple binlog The files are separated by spaces ) | mysql -u root -p 111111
XtraBackup The physical backup
Why physical backup is needed
- Direct backup InnoDB The underlying data file
- Export does not require conversion , Fast
- Less pressure on the database when working
- It is easier to realize incremental backup
Is it feasible to copy raw files directly ?
- Theoretically feasible , But there are many problems :
- Backup at the same time frm file 、ibd file 、binlog file 、redo log Documents, etc.
- Restoring on different versions of databases and operating systems may have compatibility problems
- Must be cold backed up , Affect the business
Realize Physics + heat + Full volume backup
- Ideas : utilize redo log, Backup ibd file + During backup redo log
- 1、 start-up redo log Listening to the thread , Start collecting redo log
- 2、 Copy ibd Data files
- 3、 Stop collecting redo log
- 4、 Add FTWRL Lock copy metadata frm
Realize Physics + heat + Incremental backup
- Ideas : Same as the full volume level
- How to determine the increment : According to each page LSN Number , Identify changing pages
Realize physical restore
- Ideas :mysqld crash Crash recovery process is similar
- Restore ibd file , replay redo log
ibbackup
- Current name MySQL Enterprise Backup,InnoDB Official product
- Realize the above functions , Excellent performance
XtraBackup
- Percona The open source version developed by the company , Realization ibbackup All functions
- XtraBackup 8.0 -> MySQL 8.0
- XtraBackup 2.4 -> MySQL 5.1,5.5,5.6,5.7
XtraBackup Full use method
Backup :
innobackupex --user=root --password=111111 backdir/ # backdir: Backup folderData restore :( Stop mysqld)
innobackupex --copy-back backdir/xxxx-xx-xx/
XtraBackup Incremental usage
Incremental backup :
innobackupex --user=root --password=111111 --incremental backdir/ --incremental-basedir='/backdir/xxxx-xx-xx'Merge incremental backup into full backup
innobackupex --apply-log backdir/xxxx-xx-xx/ --incremental-dir=backdir/yyyy-yy-yy/
How to nip in the bud
Authority isolation
- The account number assigned to the business application is only DML jurisdiction
- Development students use read-only accounts
- DBA Usually use a read-only account , Switch accounts during special operations
SQL Audit
- DBA In the development environment, the audit is about to go online SQL sentence
- Develop students to modify online database , Submit to DBA perform
- Inception Automatic audit tool
Pseudo delete table
- Rename the table before deleting it , Observe whether the business is affected
- Do not delete the table directly , Add a special suffix to the table name , Delete with script
Complete process
- Back up data before going online
- Prepare the production environment accident plan
边栏推荐
- Redis notes (I) Linux installation process of redis
- Career development direction
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- Osnabrueck University | overview of specific architectures in the field of reinforcement learning
- [database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
- Monitoring - Prometheus introduction
- Lichuang EDA learning notes 14: PCB board canvas settings
- Keep an IT training diary 055- moral bitch
- Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to
- Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
猜你喜欢

The "message withdrawal" of a push message push, one click traceless message withdrawal makes the operation no longer difficult
![[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love](/img/ab/066923f1aa1e8dd8dcc572cb60a25d.jpg)
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love

GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day

Dans la recherche de l'intelligence humaine ai, Meta a misé sur l'apprentissage auto - supervisé

Crawler practice website image batch download

Network communication basic kit -- IPv4 socket structure

Monitoring - Prometheus introduction

Pagoda SSL can't be accessed? 443 port occupied? resolvent

Kiss number + close contact problem
![[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)](/img/36/e5b716f2f976eb474b673f85363dae.jpg)
[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
随机推荐
Imperial cms7.5 imitation "D9 download station" software application download website source code
Webhook triggers Jenkins for sonar detection
The requests module uses
2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
WordPress collection WordPress hang up collection plug-in
Redis transaction
Global and Chinese market of box seals 2022-2028: Research Report on technology, participants, trends, market size and share
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
The "message withdrawal" of a push message push, one click traceless message withdrawal makes the operation no longer difficult
[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
[UE4] parse JSON string
Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
MySQL data query optimization -- data structure of index
Sword finger offer:55 - I. depth of binary tree
Global and Chinese market of cell scrapers 2022-2028: Research Report on technology, participants, trends, market size and share
Practical multifunctional toolbox wechat applet source code / support traffic master
Unspeakable Prometheus monitoring practice
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
Remote work guide