MySQL版本信息:
1[root@db02 data]# mysql --version 2mysql Ver 14.14 Distrib 5.6.36, for Linux (x86_64) using EditLine wrapper
选项:
-A , --all-databases
全库备份
-B , --databases
增加建库(create)及“use库”的语句
可以直接接多个库名,同时备份多个库
-B 库1 库2
-R , --routines
备份存储过程和函数数据
--triggers
备份触发器数据
--master-data={1|2}
告诉备份后时刻的binlog位置
2 注释
1 非注释,要执行(主从复制)对恢复没什么用
--single-transaction
对innodb引擎进行热备
-F, --flush-logs
刷新binlog日志
全备
[root@db02 ~]# mysqldump -uroot -p123 -A >/backup/full.sql单库备份 使用-B的区别
1[root@db02 ~]# mysqldump -uroot -p123 test > ./test.sql 2Warning: Using a password on the command line interface can be insecure. 3 4[root@db02 ~]# mysqldump -uroot -p123 -B test > ./test_B.sql 5Warning: Using a password on the command line interface can be insecure. 6 7[root@db02 ~]# vimdiff test.sql test_B.sql多库备份 -- -B 数据1 数据库2
1[root@db02 ~]# mysqldump -uroot -p123 -B test mysql > ./test_mysql.sql 2Warning: Using a password on the command line interface can be insecure.多表备份 -- 数据库名 表名1 表名2
1[root@db02 data]# mysqldump -uroot -p123 mysql user proc > ./mysql_user_proc.sql 2Warning: Using a password on the command line interface can be insecure.--master-data=2
1[root@db02 data]# mysqldump -uroot -p123 --master-data=2 test > ./test.sql 2Warning: Using a password on the command line interface can be insecure. 3 4[root@db02 data]# vim ./test.sql 5 6-- CHANGE MASTER TO MASTER_LOG_FILE='mysql_bin.000002', MASTER_LOG_POS=262;--single-transaction
1[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction test > ./test2.sql 2Warning: Using a password on the command line interface can be insecure.-F
1[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F > ./test3.sql 2Warning: Using a password on the command line interface can be insecure.
压缩备份
1[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F | gzip > ./test3.sql.gz 2Warning: Using a password on the command line interface can be insecure. 3 4[root@db02 ~]# ll ./test3.sql.gz 5-rw-r--r-- 1 root root 818 Apr 11 17:12 ./test3.sql.gz 6 7[root@db02 ~]# file ./test3.sql.gz 8./test3.sql.tar.gz: gzip compressed data, from Unix, last modified: Wed Apr 11 17:12:48 2018解压
1[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F | gzip > ./test3.sql.gz 2Warning: Using a password on the command line interface can be insecure. 3 4[root@db02 ~]# gunzip test3.sql.gz 5或者 6[root@db02 ~]# gzip -d test3.sql.gz 7或者 8[root@db02 ~]# zcat test3.sql.gz > test3.sql
恢复
mysql> set sql_log_bin=0 # 恢复操作,不写入binlog日志中,因为写入也是无用的
mysql> source /root/test.sql
注:本博客仅供参考!