当前位置:网站首页>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
边栏推荐
- 96% of the collected traffic is prevented by bubble mart of cloud hosting
- Mysql to PostgreSQL real-time data synchronization practice sharing
- 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?
- 機器學習基礎:用 Lasso 做特征選擇
- Consul of distributed service registration discovery and unified configuration management
- Imperial cms7.5 imitation "D9 download station" software application download website source code
- Global and Chinese market of contour projectors 2022-2028: Research Report on technology, participants, trends, market size and share
- Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
- Teach you how to optimize SQL
- Leetcode 110 balanced binary tree
猜你喜欢

PHP database connection succeeded, but data cannot be inserted

Gee import SHP data - crop image

Have you entered the workplace since the first 00???

Network byte order

C language black Technology: Archimedes spiral! Novel, interesting, advanced~

7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages

Kiss number + close contact problem

WP collection plug-in free WordPress collection hang up plug-in

Monitoring - Prometheus introduction

In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c
随机推荐
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
Latex tips slash \backslash
Keepalived set the master not to recapture the VIP after fault recovery (it is invalid to solve nopreempt)
Code Execution Vulnerability - no alphanumeric rce create_ function()
Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches
Database concept and installation
How to use websocket to realize simple chat function in C #
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
Webhook triggers Jenkins for sonar detection
Global and Chinese markets for electroencephalogram (EEG) devices 2022-2028: Research Report on technology, participants, trends, market size and share
System integration meets the three business needs of enterprises
Safety tips - seat belt suddenly fails to pull? High speed police remind you how to use safety belts in a standardized way
Rhcsa day 3
WordPress collection WordPress hang up collection plug-in
Bugku Zhi, you have to stop him
I stepped on a foundation pit today
Global and Chinese market of digital impression system 2022-2028: Research Report on technology, participants, trends, market size and share
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
No clue about the data analysis report? After reading this introduction of smartbi, you will understand!