$ mysqldump --help | grep ‘set-gtid-purged’ -A 10
–set-gtid-purged[=name] Add ‘SET @@GLOBAL.GTID_PURGED’ to the output. Possible values for this option are ON, OFF and AUTO. If ON is used and GTIDs are not enabled on the server, an error is generated. If OFF is used, this option does nothing. If AUTO is used and GTIDs are enabled on the server, ‘SET @@GLOBAL.GTID_PURGED’ is added to the output. If GTIDs are disabled, AUTO does nothing. If no value is supplied then the default (AUTO) value will be considered.
从命令提供的注释中可以看出,其实该参数有3种取值:
控制是否在备份文件中添加SET @@GLOBAL.GTID_PURGED语句。
-
set-gtid-purged=0|off 不添加
-
set-gtid-purged=1|on 如果gtid没有开启,则报错;如果开启gtid,则添加。
-
如果没有提供set-gtid-purged,默认是auto,如果gtid没有开启,不添加;如果开启gtid,则添加。
如果 set-gtid-purged=1 在mysqldump文件中会有两条
SET @@SESSION.SQL_LOG_BIN= 0;
SET @@GLOBAL.GTID_PURGED=‘85e07268-dfa5-12e7-b0bc-080027a59108:1-2’;
这样导入时可能造成主备不一致情况。
所以,对GTID使用mysqldump 要注意 set-gtid-purged的指定