MySQL數據導出工具 mysqldump

MySQL版本信息:

[root@db02 data]# mysql --version
mysql  Ver 14.14 Distrib 5.6.36, for Linux (x86_64) using  EditLine wrapper

選項:

-A , --all-databases 全庫備份
-B , --databases

增長建庫(create)及「use庫」的語句mysql

能夠直接接多個庫名,同時備份多個庫sql

-B 庫1 庫2數據庫

-R , --routines 備份存儲過程和函數數據
--triggers 備份觸發器數據
--master-data={1|2}

告訴備份後時刻的binlog位置vim

2 註釋app

1 非註釋,要執行(主從複製)對恢復沒什麼用函數

--single-transaction 對innodb引擎進行熱備
-F, --flush-logs 刷新binlog日誌

 

全備 spa

[root@db02 ~]# mysqldump -uroot -p123 -A >/backup/full.sql

單庫備份 使用-B的區別日誌

[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

多庫備份 --  -B 數據1 數據庫2code

[root@db02 ~]# mysqldump -uroot -p123 -B test mysql > ./test_mysql.sql
Warning: Using a password on the command line interface can be insecure.

多表備份 --  數據庫名 表名1 表名2ip

[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.

壓縮備份

[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

解壓

[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

恢復

mysql> set sql_log_bin=0   # 恢復操做,不寫入binlog日誌中,由於寫入也是無用的

mysql> source /root/test.sql

 

注:本博客僅供參考!

相關文章
相關標籤/搜索