數據庫的模式中我開啓了gtid:
mysql>
show variables like '%gtid%';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | 1000 |
| gtid_mode |
ON
|
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-----------+
我如今數據庫中有一world的庫,而且在庫中有一個country表,如今進行備份時會提示以下警告:
[root@smiletest data]# mysqldump -uroot -p -R -e --triggers --master-data=2 --single-transaction world country >/tmp/countryno.sql
Enter password:
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass
--set-gtid-purged=OFF.
To make a complete dump, pass --all-databases --triggers --routines --events.
咱們來對比下加了 --set-gtid-purged=OFF和不加的區別
countryno.sql是沒有加--set-gtid-purged=OFF
[root@smiletest data]# mysqldump -uroot -p -R -e --triggers --master-data=2 --single-transaction world country >/tmp/countryno.sql
countryyes.sql是加--set-gtid-purged=OFF
[root@smiletest data]# mysqldump -uroot -p -R -e --triggers --master-data=2 --single-transaction --set-gtid-purged=OFF world country >/tmp/countryyes.sql
Enter password:
沒有加
--set-gtid-purged=OFF
的裏面會多幾條語句
SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
SET @@SESSION.SQL_LOG_BIN= 0;
-- GTID state at the beginning of the backup
SET @@GLOBAL.GTID_PURGED='e024c334-8b64-11e9-80dc-fa163e4bfc29:1-761734';
如今咱們進行導入剛沒有加--set-gtid-purged=OFF備份的/tmp/countryno.sql語句
mysql> show master status;
+------------------+----------+--------------+------------------+-----------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-----------------------------------------------+
| mysql-bin.000013 | 85019 | | | e024c334-8b64-11e9-80dc-fa163e4bfc29:
1-761735
|
+------------------+----------+--------------+------------------+-----------------------------------------------+
1 row in set (0.00 sec)
mysql> source /tmp/countryno.sql
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-----------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-----------------------------------------------+
| mysql-bin.000013 | 85019 | | | e024c334-8b64-11e9-80dc-fa163e4bfc29:1-
761735 |
+------------------+----------+--------------+------------------+-----------------------------------------------+
1 row in set (0.00 sec)
結論發現,gtid事務和 Position都沒有增長
如今咱們進行導入剛加--set-gtid-purged=OFF備份的/tmp/countryyes.sql語句
mysql> drop table country;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-----------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-----------------------------------------------+
| mysql-bin.000013 | 112669 | | | e024c334-8b64-11e9-80dc-fa163e4bfc29:1-
761742 |
+------------------+----------+--------------+------------------+-----------------------------------------------+
1 row in set (0.00 sec)
mysql> source /tmp/countryyes.sql
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-----------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-----------------------------------------------+
| mysql-bin.000013 | 139929 | | | e024c334-8b64-11e9-80dc-fa163e4bfc29:1-
761747 |
+------------------+----------+--------------+------------------+-----------------------------------------------+
1 row in set (0.00 sec)
mysql>
結論發現,gtid事務和 Position都增長了
結論
加了--set-gtid-purged=OFF時,在會記錄binlog日誌,若是不加,不記錄binlog日誌,因此在咱們作主從用了gtid時,用mysqldump備份時就要加--set-gtid-purged=OFF,不然你在主上導入恢復了數據,主沒有了binlog日誌,同步則不會被同步。