MySQL database (four) - Database Backup and Recovery

Database Backup and Recovery

A backup of the database

The type of backup and understanding

Physical backup: 1 cold backup (offline backup): the database is in a closed state, go directly into the database file

                  Features: Backup fast, simple reply

                  2. hot backup (online backup): In the case of the database operation, the method archivelog mode database backup mode

                  Features: If you have a cold backup last night and again today, hot backup file, in the event of a problem, you can use these data recovery for more information

                  3. Backup Temperature: Temperature is generally periodic backup power, the content is updated in accordance with

Logical backup: a full backup: now all mounted from the database to the backup

                  2. A differential backup: This section from the last backup to the backup now

                  3. Incremental backup: an increase from the last backup to the current on the last backup

Specific backup method

Physical backup package

tar zcf /mysqlbak/mysql.$(date +%Y%m%d%S).tar.gz /usr/local/mysql/date/*

Special tool to back up (export database to log the contents of the database)

Back up all libraries: mysqldump --all-uroot--p123456-Databases> /mysqlbak/exercise.sql

Backup designated library: mysqldump-uroot--p123456 Exercise> /mysqlbak/exercise.sql

Backup table: the mysqldump -uroot--p123456 Exercise A> /mysqlbak/exercise.A.sql

Incremental Backup

Binary logs provided by MySQL

vim /etc/my.cnf

max_binlog_size   \\ set the maximum binary log files

= MySQL-bin-log bin  \\ enable binary logging

Enable to generate binary log file: /usr/local/mysql/data/master-bin.000001

log-bin=/usr/local/mysql/log/mysql-bin

flush logs;

Third-party backup tools

phpMyAdmin

Navicat Premium

Etc., etc. . . . . .

Second, restore the database

1. Direct decompression backup database to extract the packet data directory

2.mysqldump Exporting Data Recovery

method one:

First create the database, go to the library (library name and the name of the need to restore the same)

mysql>source /mysqlbak/exercise.sql

Method Two:

First create the database, exit the database (the name with the library name needs to be restored as)

mysql -uroot -p123456 exercise < /mysqlbak/exercise.sql

3. binary log recovery

To see the time by looking at the node position binary or below

Use a compiler that comes with the installation tool to view and restore mysqlbinlog

View binaries: mysqlbinlog MySQL-bin.00001

Based node recovery time (Note command format)

mysqlbinlog --stop-datetime='2020-03-06 15:28:26' /usr/local/mysql/data/master-bin.000001 | mysql -uroot -p123456

Location-based recovery (Note command format)

mysqlbinlog --stop-position='1935' /usr/local/mysql/data/master-bin.000001 |mysql -uroot -p123456

 

Published 37 original articles · won praise 6 · views 10000 +

Guess you like

Origin blog.csdn.net/feili12138/article/details/104651929