導入報錯
[root@redis02 data]# mysql -u root -p < ht.sql
Enter password:
ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.
簡單粗暴的玩法先把活干拉在說,vi ht.sql 刪除一下幾行
--
-- GTID state at the beginning of the backup
--
SET @@GLOBAL.GTID_PURGED='f0019921-6d42-11e8-bd74-0800272bcfc4:1-6,
f27d825f-792f-11e8-b745-0800272bcfc4:1-6';
在導入數據就沒報錯,這個問題在導出數據時就告警拉
[root@redis01 data]# mysqldump -u root -p --databases ht > ht.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.
查看gtid

1 mysql> show global VARIABLES LIKE '%GTID%'; 2 +---------------------------------------------------+----------------------------------------------------+ 3 | Variable_name | Value | 4 +---------------------------------------------------+----------------------------------------------------+ 5 | binlog_gtid_simple_recovery | ON | 6 | enforce_gtid_consistency | ON | 7 | group_replication_allow_local_disjoint_gtids_join | OFF | 8 | group_replication_gtid_assignment_block_size | 1000000 | 9 | gtid_executed | f0019921-6d42-11e8-bd74-0800272bcfc4:1-6, 10 f27d825f-792f-11e8-b745-0800272bcfc4:1-6 | 11 | gtid_executed_compression_period | 1000 | 12 | gtid_mode | ON | 13 | gtid_owned | | 14 | gtid_purged | | 15 | session_track_gtids | OFF | 16 +---------------------------------------------------+----------------------------------------------------+ 17 10 rows in set (0.00 sec)
提示的很明顯,不想用gtid可以把它關閉,改成下面就正常。
mysqldump -u root -p --set-gtid-purged=OFF --databases ht > ht.sql
如果表有外鍵導入時也可能報錯,如果報錯用 FOREIGN_KEY_CHECKS解決
set FOREIGN_KEY_CHECKS=0; #在導入的腳本命令行最前面設置為不檢查外鍵約束
。。。。。。。。。。。。 #導入數據的命令行
set FOREIGN_KEY_CHECKS=1; #在導入后恢復檢查外鍵約束
任何工具都有一定的局限性用在合適的地方就好。