mysql basis of the practical operation of backup and recovery

First, the binary-based recovery ***

1, considered a good period of time to restore the data, redirect input file to bin.sql

[root@ren7 mysql]# mysqlbinlog --start-datetime="2019-09-07 20:07:32" --stop-datetime="2019-09-07 20:12:00" mysql-bin.000001 > bin.sql
[root@ren7 mysql]# chown mysql.mysql bin.sql

Execution bin.sql file restore (under the sql statement)

MariaDB [ren]> source /var/lib/mysql/bin.sql

2, according to which the position of the last recovery

MariaDB [ren]> delete from test where id is null;
Query OK, 1 row affected (0.00 sec)
MariaDB [ren]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 |      690 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
[root@ren7 mysql]# mysqlbinlog /var/lib/mysql/mysql-bin.000002 --stop-position=518 | mysql -uroot -proot

Second, the backup ***-based backup tool mariabackup

 

 

 

Third, the backup (logical backup tool) tool based mysqldump ***

Database backup testdb # ( - locking l behalf of all the tables the single database backup database; - Lock all tables for all databases during backup all databases when x) 
the mysqldump - -uroot - PROOT - l - Databases testdb> testdb.sql 
# Back up all databases 
mysqldump - -uroot - PROOT - All-databases> all_databases.sql 
# Students under the table testdb backup database 
mysqldump - -uroot - PROOT testdb Students > students.sql 
Students table and classes under the table # testdb backup database 
mysqldump - -uroot - PROOT the testdb classes Students. >  both_tables.sql
# restoring data (sql command line) 
Source testdb.sql
Other common options:
 - Master-Data: 
            0 : indicates when using mysqldump backup, does not correspond to the binary log file location record, this value is explicitly set to 0 and this option is not the same as the effect of
             1 : shows the use when mysqldump backup, binary log files corresponding to the recording position, this is the default value
             2 :
 - the flush-logs: 
- routines: indicates the time of backup, stored procedures, and backup will be stored functions 
- Triggers: indicates the time of backup, the trigger is backed up 
- events: said in a backup, event table will be backed up  

Fourth, lvm2-based backup

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/renyz/p/11483066.html