Question

I have 2 databses X "production" and Y "testing

Database X should be identical to Y in structure. However, they are not because I mad many changes to the production. Now, I need to somehow to export X and import it into Y without breaking any replications.

I am thinking to do mysql dump but I don't want to case any issue to replication this is why I am asking this question to confirm.

Here are the step that I want to follow

  1. back up production. (ie. mysqldump -u root -p --triggers --routines X > c:/Y.sql)
  2. Restore it. (ie. mysql -u root -p Y < c:\Y.sql)

Will this cause any issues to the replication?

I believe the dump will execute everything and save it into it's bin log and the slave will be able to see it and replicate it with no problems.

Is what I am trying to do correct? will it cause any replication issues?

thanks

Was it helpful?

Solution

Yes, backing up from X and restoring to Y is a normal operation. We often call this "reinitializing the replica."

This does interrupt replication. There's no reliable way to restore the data at the same time as letting the replica continue to apply changes, because the changes the replica is processing are not in sync with the snapshot of data represented by the backup. You could overwrite changed data, or miss changes, and this would make the replica totally out of sync.

So you have to stop replication on the replica while you restore.

Here are the steps for a typical replica reinitialization:

  1. mysqldump from the master, with the --master-data option so the dump includes the binary log position that was current at the moment of the dump.
  2. Stop replication on the replica.
  3. Restore the dump on the replica.
  4. Use CHANGE MASTER to alter what binary log coordinates the replica starts at. Use the coordinates that were saved in the dump.
  5. Start replication on the replica.

Re your comment:

Okay, I understand what you need better now.

Yes, there's an option for mysqldump --no-data so the output only includes the CREATE TABLE and other DDL, but no INSERT statements with data. Then you can import that to a separate database on the same server. And you're right, by default DDL statements are added to the binary log, so any replication replicas will automatically run the same statements.

You can even do the export & import in just two steps like this:

$ mysqladmin create newdatabase
$ mysqldump --no-data olddatabase | mysql newdatabase
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top