I have a file called db.sql; this file contains the data for one database. I want to import this data into a database called db in the newly established master/replica structure.
I used mysql -u USER -p'PASS' db < db.sql command to import the database into the master server. After import, The date was inserted into master server successfully but did not insert into the replica server. (But still, work without error)
I check the content of the db.sql file, which includes:
SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
SET @@SESSION.SQL_LOG_BIN= 0;
SET @@GLOBAL.GTID_PURGED='server-1:1-376,
server-2:1-2086154';
#end of the file
SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;
I know the reason for that is disabling binlog, yet I have three questions:
- I have many backup files exported in this way; how to import them into my current
masterserver, then it goes to thereplicaserver. (I think If I remove those lines, it will fix my problem but is there anyways to do it directly by MySQL?) - For newly exported backups, how to prevent this issue in a way that can import directly? The below script produce the
db.sqlfile.
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
mysql ${MYSQL_CONN} -ANe"STOP SLAVE" 2> /dev/null
mysqldump ${MYSQL_CONN} --single-transaction --quick ${DB_NAME} 2> /dev/null > ${OUTPUT_PATH}/db.sql
mysql ${MYSQL_CONN} -ANe"START SLAVE" 2> /dev/null
- The backup files come from different master/replicas with different
GLOBAL.GTID_PURGED; is this causing any issues? If yes, how to solve it?
https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html says:
This matches what you are seeing in your dump output.
A bit later, the same page says:
I recommend setting
--set-gtid-purged=OFFwhen you runmysqldump.