当前位置:网站首页>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
边栏推荐
- Imperial cms7.5 imitation "D9 download station" software application download website source code
- Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
- Global and Chinese market of small batteries 2022-2028: Research Report on technology, participants, trends, market size and share
- 150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
- A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
- [UE4] parse JSON string
- Solve the problems encountered by the laravel framework using mongodb
- Safety tips - seat belt suddenly fails to pull? High speed police remind you how to use safety belts in a standardized way
- 60 year old people buy medical insurance and recommend a better product
- Short math guide for latex by Michael downs
猜你喜欢

Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi

If you have just joined a new company, don't be fired because of your mistakes

Add token validation in swagger

Crawler practice website image batch download

Ai aide à la recherche de plagiat dans le design artistique! L'équipe du professeur Liu Fang a été embauchée par ACM mm, une conférence multimédia de haut niveau.

Rhcsa day 2
![[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
![Backpropagation formula derivation [Li Hongyi deep learning version]](/img/ef/f76eae39c4f8716a0030a60c85b09c.gif)
Backpropagation formula derivation [Li Hongyi deep learning version]

Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory

Imperial cms7.5 imitation "D9 download station" software application download website source code
随机推荐
POSTECH | option compatible reward reverse reinforcement learning
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
Global and Chinese market of contour projectors 2022-2028: Research Report on technology, participants, trends, market size and share
Résumé des outils communs et des points techniques de l'examen PMP
WP collection plug-in free WordPress collection hang up plug-in
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
Global and Chinese market of small batteries 2022-2028: Research Report on technology, participants, trends, market size and share
[development team follows] API specification
Global and Chinese market of handheld melanoma scanners 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of thin film deposition systems 2022-2028: Research Report on technology, participants, trends, market size and share
150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
Node write API
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
Contest3145 - the 37th game of 2021 freshman individual training match_ J: Eat radish
Setting methods, usage methods and common usage scenarios of environment variables in postman
Recent learning fragmentation (14)
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
The "message withdrawal" of a push message push, one click traceless message withdrawal makes the operation no longer difficult
The 37 year old programmer was laid off, and he didn't find a job for 120 days. He had no choice but to go to a small company. As a result, he was confused
Record a problem that soft deletion fails due to warehouse level error