备份大小在10G以下,可以用mysqldump进行备份(du -sh 数据库数据文件夹----查看数据库数据大小) mysqldump是单线程备份,单线程恢复的,速度比较慢 备份语句 前提:数据库用了gtid进行主从复制的 /usr/local/mysql/bin/mysqldump -uroot -p123456 --single-transaction --master-data=2 -A > /root/1.sql --single-transaction #保证数据一致性,mysqldump在执行备份语句那一时刻,他会备份到那时刻的数据。跟xtrabackup不一样,xtrabackup是备份到备份完数据那一刻的数据。 --master-data=2 #在bin-log日志里记录备份到了哪个位置 注意:这里没有加上 --set-gtid-purged=OFF 默认 --set-gtid-purged=ON 好啦,备份完之后,我们测试一下,把数据导入另外一个数据库: mysql> reset master; Query OK, 0 rows affected (0.04 sec) #清空这个数据库的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: 开始导入数据: /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) #可见已经导入数据库,gtid那边已经执行过语句了。但是这些gtid都是其他数据库的。 好啦,我们看下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日志大小没有发生变化,如果有写入了bin-log日志,大小应该是32M的 结论: 开启gtid后,备份的时候使用--set-gtid-purged=ON 备份出来的数据,导入到其他数据库里,是不会写入bin-log日志的。但是会执行gtid语句,而且这些gtid语句的uuid是备份这数据数据库的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) #开始导入数据 /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日志写入了内容 查看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是这台导入数据的数据库的uuid。 结论: --set-gtid-purged=OFF 会写入bin-log gtid会是导入数据的那台mysql的uuid |
|