mysqldump export data backup --set-gtid-purged=OFF

When the Mysql database is exported, backed up and restored from the master and slave databases, it is necessary to pay attention to whether the GTID mode of the database is enabled. If it is enabled, the mysqldump command should be added with the parameter --set-gtid-purged=OFF when mysqldump data.

For details, please refer to the reprint:

The following are the first 30 rows of a.sql exported by mysqldump:

[root@aaa0-D14-042 mysqlbackup]# head -30 t1.sql 
-- MySQL dump 10.13  Distrib 5.6.24-72.2, for Linux (x86_64)
--
-- Host: localhost    Database: yyf
-- ------------------------------------------------------
-- Server version       5.6.24-72.2-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

<!--重点注意下面这两行-->
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='18f9a804-343b-11e5-a21d-b083fed01601:1-2';
--
-- Table structure for table `t1`
--
DROP TABLE IF EXISTS `t1`;

For databases with a general master-slave architecture, usually the relevant import operations only need to be performed on the master (main database) side, but as shown in the key note section in the export a.sql code, the session-level sql_log_bin is disabled, so in the target When the t1 table is imported into the server, the corresponding bin log log will not be generated, so the table and its data will not be synchronized to the slave side. This is something to be aware of when testing the database.

After testing, it is found that when the database is in GTID mode, the above will appear. Therefore, if the database uses GTID mode, when mysqldumps data, the parameter --set-gtid-purged=OFF should be added to the warning prompt, and the exported data should be sql file (code in unmarked locations):

-- MySQL dump 10.13  Distrib 5.6.26, for Linux (x86_64)
--
-- Host: localhost    Database: yyf
-- ------------------------------------------------------
-- Server version       5.6.26-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `t1`;
` -- DROP TABLE IF EXISTS `t1`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325063262&siteId=291194637