We are creating a few slave servers using an existing single mysql server. We know all about the my.cnf settings, user creation, etc etc. Both on the master and slave side. We are more interested about the initial database creation on the slaves.
The existing server will be the master, the new ones will all be slaves.
We were wondering the procedure when creating new slaves using an existing database.
Here is what we have done, please let us know if this is correct.
a) Existing single mysqld taken offline (what will in the end be the master).
b) Via my.cnf, we changed the port from the 3306 to something random. We did this to make sure that when we bring the server up to do the mysqldump, no writes are made. This will ensure, 100% that the dump will be 100% recent.
c) mysqldump of existing database made.
d) mysqld taken offline again.
e) binlogs purged. We did this by simply deleting them. Which appears to be ok, since having a peak at the binlog after starting mysqld back up, there were re-initialized back at 000001.
f) Existing mysqld server brought up using old port, so our webservice could go back up while we set everything up.
So… If my thinking is correct, at this point we should have:
mysqldump + binlogs = 100% current database.
The reason I am asking all of this is because doing a:
mysql DATABASE < dumpfile.sql
Is taking about 2 hours, with probably another 2 hours to go.
Will we have any major issues with the slave ‘catching up’ with 3-4 hours worth of binlogs?
Thank you kindly.
You don’t necessarily have to take mysqld offline or change the port. You can use
FLUSH TABLES WITH READ LOCKto ensure no writes happen while you’re noting the binlog position and creating the dump.Restoring a dump usually takes a long time, probably a lot longer than it took to create the dump. If your master is recording a very high rate of new changes, then yes, it may take a while for the replica to catch up once you finish the restore on the replica and start replication.
An alternative you can use, if shutting down mysqld is acceptable, is to copy the physical data directory from master to replica, instead of doing the dump and restore. So initializing the replica can be very quick, basically just as long as it takes to run
rsyncto copy the files from one server to the other.note: You must shut down mysqld on master and replica as you do this, otherwise you have a risk that some of the data is buffered and won’t be included in the file copy. Remember to check file ownership and permissions on the replica before starting mysqld on the replica.
You should read these sections from the manual for more details: