備份大小在10G以下,可以用mysqldump進行備份(du -sh 數(shù)據(jù)庫數(shù)據(jù)文件夾----查看數(shù)據(jù)庫數(shù)據(jù)大?。?/p>
mysqldump是單線程備份,單線程恢復的,速度比較慢
備份語句
前提:數(shù)據(jù)庫用了gtid進行主從復制的
/usr/local/mysql/bin/mysqldump -uroot -p123456 --single-transaction --master-data=2 -A > /root/1.sql
--single-transaction #保證數(shù)據(jù)一致性,mysqldump在執(zhí)行備份語句那一時刻,他會備份到那時刻的數(shù)據(jù)。跟xtrabackup不一樣,xtrabackup是備份到備份完數(shù)據(jù)那一刻的數(shù)據(jù)。
--master-data=2 #在bin-log日志里記錄備份到了哪個位置
注意:這里沒有加上 --set-gtid-purged=OFF 默認 --set-gtid-purged=ON
好啦,備份完之后,我們測試一下,把數(shù)據(jù)導入另外一個數(shù)據(jù)庫:
mysql> reset master;
Query OK, 0 rows affected (0.04 sec)
#清空這個數(shù)據(jù)庫的bin-log日志和gtid記錄,此時通過show slave status\G 查看信息都是空的
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
開始導入數(shù)據(jù):
/usr/local/mysql/bin/mysql -uroot -p123456 < /root/1.sql
進入mysql查看,show slave status\G
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 6bf23ca7-f1c9-11e9-bc34-0050562b3b5a:1,
f50c4171-f1c4-11e9-8de8-0050563a3356:1-68735
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
#可見已經(jīng)導入數(shù)據(jù)庫,gtid那邊已經(jīng)執(zhí)行過語句了。但是這些gtid都是其他數(shù)據(jù)庫的。
好啦,我們看下bin-log日志
[root@localhost datanode1]# ls -lh bin-log-mysqld5.000001
-rw-r-----. 1 mysql mysql 154 Sep 12 01:57 bin-log-mysqld5.000001
#看到bin-log日志大小沒有發(fā)生變化,如果有寫入了bin-log日志,大小應該是32M的
結(jié)論:
開啟gtid后,備份的時候使用--set-gtid-purged=ON
備份出來的數(shù)據(jù),導入到其他數(shù)據(jù)庫里,是不會寫入bin-log日志的。但是會執(zhí)行gtid語句,而且這些gtid語句的uuid是備份這數(shù)據(jù)數(shù)據(jù)庫的uuid
備份使用 --set-gtid-purged=OFF的情況
/usr/local/mysql/bin/mysqldump -uroot -p123456 --single-transaction --master-data=2 --set-gtid-purged=OFF -A > /root/1.sql
#清掉bin-log和gtid信息
reset master;
#查看gtid信息
show slave status\G
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
#開始導入數(shù)據(jù)
/usr/local/mysql/bin/mysql -uroot -p123456 < 1.sql
查看bin-log日志大小
-rw-r-----. 1 mysql mysql 32M Sep 12 02:24 /data/mysql/datanode1/bin-log-mysqld5.000001
#bin-log日志寫入了內(nèi)容
查看gtid信息
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 55001361-d483-11e9-ab0d-0050563aec90:1-177
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
#可以看得出這個gtid里的Uuid是這臺導入數(shù)據(jù)的數(shù)據(jù)庫的uuid。
結(jié)論:
--set-gtid-purged=OFF
會寫入bin-log
gtid會是導入數(shù)據(jù)的那臺mysql的uuid