MySQL version information:
[root@db02 data]# mysql --version mysql Ver 14.14 Distrib 5.6.36, for Linux (x86_64) using EditLine wrapper
Options:
-A , --all-databases Full database backup -B , --databases Add statements for creating a library (create) and "use library"
Multiple library names can be directly connected, and multiple libraries can be backed up at the same time
-B library1 library2
-R , --routines Back up stored procedure and function data --triggers Backup trigger data --master-data={1|2} Tell the binlog location at the moment after backup
2 Notes
1 non-comment, to perform (master-slave replication) is not useful for recovery
--single-transaction Hot standby for the innodb engine -F, --flush-logs flush binlog log
fully prepared
[root@db02 ~]# mysqldump -uroot -p123 -A >/backup/full.sql
The difference between using -B for single database backup
[root@db02 ~]# mysqldump -uroot -p123 test > ./test.sql Warning: Using a password on the command line interface can be insecure. [root@db02 ~]# mysqldump -uroot -p123 -B test > ./test_B.sql Warning: Using a password on the command line interface can be insecure. [root@db02 ~]# vimdiff test.sql test_B.sql
Multi-database backup -- -B data 1 database 2
[root@db02 ~]# mysqldump -uroot -p123 -B test mysql > ./test_mysql.sql Warning: Using a password on the command line interface can be insecure.
Multi-table backup -- database name table name 1 table name 2
[root@db02 data]# mysqldump -uroot -p123 mysql user proc > ./mysql_user_proc.sql Warning: Using a password on the command line interface can be insecure.
--master-data=2
[root@db02 data]# mysqldump -uroot -p123 --master-data=2 test > ./test.sql Warning: Using a password on the command line interface can be insecure. [root@db02 data]# vim ./test.sql -- CHANGE MASTER TO MASTER_LOG_FILE='mysql_bin.000002', MASTER_LOG_POS=262;
--single-transaction
[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction test > ./test2.sql Warning: Using a password on the command line interface can be insecure.
-F
[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F > ./test3.sql Warning: Using a password on the command line interface can be insecure.
compressed backup
[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F | gzip > ./test3.sql.gz Warning: Using a password on the command line interface can be insecure. [root@db02 ~]# ll ./test3.sql.gz -rw-r--r-- 1 root root 818 Apr 11 17:12 ./test3.sql.gz [root@db02 ~]# file ./test3.sql.gz ./test3.sql.tar.gz: gzip compressed data, from Unix, last modified: Wed Apr 11 17:12:48 2018
decompress
[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F | gzip > ./test3.sql.gz Warning: Using a password on the command line interface can be insecure. [root@db02 ~]# gunzip test3.sql.gz 或者 [root@db02 ~]# gzip -d test3.sql.gz 或者 [root@db02 ~]# zcat test3.sql.gz > test3.sql
recover
mysql> set sql_log_bin=0 # Recovery operation, do not write to the binlog log, because writing is also useless
mysql> source /root/test.sql
Note: This blog is for reference only!