# mysqldump --help|grep gtid-purged -A8--set-gtid-purged[=name] Add "SET @@GLOBAL.GTID_PURGED" to the output. Possiblevalues for this option are ON, OFF and AUTO. If ON isused and GTIDs are not enabled on the server, an error isgenerated. If OFF is used, this option does nothing. IfAUTO is used and GTIDs are enabled on the server, "SET@@GLOBAL.GTID_PURGED" is added to the output. If GTIDsare disabled, AUTO does nothing. If no value is suppliedthen the default (AUTO) value will be considered.这个参数用于控制在导出数据库时是否导出GTID,针对已开启GTID的mysql实例就是说导出的数据中已经包含了这些GTID,因此在从库开启从之后需要被跳过缺省值为AUTO,如果导出时指定为OFF,则在从库开启从之后会收到error 1236
演示环境(root@Master)[(none)]>show variables like "version";+---------------+------------+| Variable_name | Value|+---------------+------------+| version | 5.7.12-log |+---------------+------------+--创建需要复制的数据库tempdb与testdb(root@Master)[(none)]>create database tempdb;(root@Master)[(none)]>use tempdb;(root@Master)[tempdb]>create table tb(`userId` int);(root@Master)[(none)]>create database testdb;(root@Master)[(none)]>use testdb;(root@Master)[testdb]>create table tb(`userId` int);--主库端执行sql,使用如下脚本# more insert_id.sh #/bin/shcnt=1while [ $cnt -le 10000 ]domysql -uroot -ppass -e "insert into tempdb.tb(userId) values($cnt);insert into testdb.tb(userId) values($cnt)"let cnt=$cnt+1 sleep 1 echo "Insert $cnt"done--执行脚本# ./insert_id.sh mysql: [Warning] Using a password on the command line interface can be insecure.Insert 2mysql: [Warning] Using a password on the command line interface can be insecure.Insert 3mysql: [Warning] Using a password on the command line interface can be insecure.Insert 4 ...........--dump导出库文件 # mysqldump --single-transaction --triggers --routines --events --user=root --password=pass > --databases tempdb testdb>/tmp/multidb.sql--dump文件的内容# more /tmp/multidb.sql-- MySQL dump 10.13Distrib 5.7.12, for linux-glibc2.5 (x86_64)---- Host: localhostDatabase: tempdb-- -------------------------------------------------------- Server version 5.7.12-log-- 非重要的信息省略 SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;SET @@SESSION.SQL_LOG_BIN= 0;---- GTID state at the beginning of the backup----GTID信息,重要,用于主从复制跳过)SET @@GLOBAL.GTID_PURGED="1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2318";---- Current Database: `tempdb`--CREATE DATABASE /*!32312 IF NOT EXISTS*/ `tempdb` /*!40100 DEFAULT CHARACTER SET latin1 */;USE `tempdb`;---- Table structure for table `tb`--DROP TABLE IF EXISTS `tb`;/*!40101 SET @saved_cs_client = @@character_set_client */;/*!40101 SET character_set_client = utf8 */;CREATE TABLE `tb` (`userId` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;/*!40101 SET character_set_client = @saved_cs_client */;---- Dumping data for table `tb`--LOCK TABLES `tb` WRITE;/*!40000 ALTER TABLE `tb` DISABLE KEYS */;INSERT INTO `tb` VALUES (1),(2),(3),(4),(5);/*!40000 ALTER TABLE `tb` ENABLE KEYS */;UNLOCK TABLES;---- Dumping events for database "tempdb"------ Dumping routines for database "tempdb"------ Current Database: `testdb`--CREATE DATABASE /*!32312 IF NOT EXISTS*/ `testdb` /*!40100 DEFAULT CHARACTER SET latin1 */;USE `testdb`;---- Table structure for table `tb`--DROP TABLE IF EXISTS `tb`;/*!40101 SET @saved_cs_client = @@character_set_client */;/*!40101 SET character_set_client = utf8 */;CREATE TABLE `tb` (`userId` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;/*!40101 SET character_set_client = @saved_cs_client */;---- Dumping data for table `tb`--LOCK TABLES `tb` WRITE;/*!40000 ALTER TABLE `tb` DISABLE KEYS */;INSERT INTO `tb` VALUES (1),(2),(3),(4),(5);/*!40000 ALTER TABLE `tb` ENABLE KEYS */;UNLOCK TABLES;---- Dumping events for database "testdb"---- 在上面dump出来的每个表中可以看到导出的时候已经产生了数据1-5-- Dumping routines for database "testdb"--SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;--将导出文件复制到从服务器[root@node233 ~]# scp /tmp/multidb.sql 192.168.1.245:/tmp