I have a 300 GB mysql database which i want to migrate to another server in order to setup Master-Master replication between the two and my main aim is to achieve this with least possible downtime.
My database has only one table around 30GB where inserts are happening round the clock. All the other tables are history tables(static).
1) What will be the best way to go forward in this case?
-
Taking mysqldump of the whole database and transferring the dump to
other server and importing it to the new server will do the job i want to achieve but will take a lot of
downtime (maybe more than 14hrs) which is not permissible. -
Or can i take individual table dumps for the static tables without stopping mysql and import it to new server ,and after all this is over, take downtime for the single active table so that no new inserts will happen and both my databases will be in sync? First of all is it possible to do such a thing ? and if possible what issues it might present while setting up a master-master replication?
- Or is there any other method to do this with very less downtime?
Best Answer
This solution can be done with mysqldump but with a bit of a risk
For the sake of this example, suppose you have the following:
mydb
10.20.30.40
10.20.30.50
root
on both source and target DB Serverswhatever
on both source and target DB Serversmysql-bin
Here are your steps
STEP 01 : Create Replication User
On the Live Master, run the following
STEP 02 : Set Up Replication
On the target DB Server, run the following:
If you have GTID enabled on source and target servers, do this:
If you do not have GTID enabled on source and target servers, do this:
STEP 03 : Create a script to perform live mysqldump and load
Create a shell script called
live_dump_and_load.sh
Put the following lines in it
STEP 04 : Run the shell script
STEP 05 : Monitor the run log
STEP 06 : Start Replication
When the dump is loaded onto the target server, go to the target server and run
GIVE IT A TRY !!!