当前位置:网站首页>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-logs
Add 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 folder
Data 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
边栏推荐
- Slurm view node configuration information
- How to use STR function of C language
- A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
- Network byte order
- Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
- Problems and solutions of several concurrent scenarios of redis
- AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
- The difference between MCU serial communication and parallel communication and the understanding of UART
- Data collection and summary
- Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
猜你喜欢
Node write API
Node solves cross domain problems
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
長文綜述:大腦中的熵、自由能、對稱性和動力學
MySQL workbench use
1day vulnerability pushback skills practice (3)
Bugku Zhi, you have to stop him
Add token validation in swagger
Rhcsa day 3
Lichuang EDA learning notes 14: PCB board canvas settings
随机推荐
1day vulnerability pushback skills practice (3)
What are the conditions for the opening of Tiktok live broadcast preview?
How to use STR function of C language
Talking about custom conditions and handling errors in MySQL Foundation
2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
Unity knapsack system (code to center and exchange items)
Global and Chinese market for travel wheelchairs 2022-2028: Research Report on technology, participants, trends, market size and share
JS object definition
Johnson–Lindenstrauss Lemma
ZABBIX API batch delete a template of the host
Comment la transformation numérique du crédit d'information de la Chine passe - t - elle du ciel au bout des doigts?
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
Jenkins continuous integration environment construction V (Jenkins common construction triggers)
[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
WordPress collection WordPress hang up collection plug-in
Code Execution Vulnerability - no alphanumeric rce create_ function()
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
Gee import SHP data - crop image