سؤال

Can anyone think of a good way to sync a mysql database with another mysql database before the server starts up? I thought maybe i could rsync the directories in rc.d, but that seems dicey. The server's running on FreeBSD.

Thanks.

For clarification:

Alright. I am setting up mysql as a session store for a php web application. I have written a class that overrides php's session methods with methods that offer benefits important to our web app. In the interest of the maximum speed, the main mysql server is storing its data in a tmpfs partition. It replicates to a server with an SSD.

In the event of a failure, my session management class will automatically roll over to the slave, but when the master reboots, and the mysql service starts, session requests will be redirected at it, but there will be no data present. Ergo, I need to get the data from the slave during the boot sequence of the master.

هل كانت مفيدة؟

المحلول

If both mysql servers are down: rsync-ing the datadir (which I assume is not in rc.d, as that would be weird?) before staring them both is not a problem, and works fine as long as the version of mysql on the new server is higher or equal (you may need to run mysql_upgrade on a higher version).

If the first is running, you preferable want a master-slave scenario, starting from a hotcopy. With Percona's Xtrabackup you can back up a live database including InnoDB table with the minimal amount of locking possible (but some locking still occurs!), you copy that datadir to the new server. Now, it is as 'in sync' as you can get it, but the 1st server is still working, so data is changing constantly. To get it in sync with those changes again set it up as a slave at the point stored in the xtrabackup_binlog_info file.

نصائح أخرى

Yes, if the mysqld daemon is shut down, you can rsync a data directory to another location. Both the origin and destination servers should have their mysql daemons shut down.

It is not safe to rsync the data directory of a running mysqld instance, nor to copy it to a running mysqld instance. This is because at any time, part of the data could still be in memory, not yet written to disk. If you use only rsync to copy it, you'll get an incomplete database and pretty much guarantee to corrupt it.

Another option is to use Percona XtraBackup, which performs a quick, online, physical copy of data. It includes a mode to send its output over a network so you can use it to initialize a new server immediately.

See http://www.percona.com/doc/percona-xtrabackup/2.1/howtos/recipes_ibkx_stream.html for examples of doing a streaming backup.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top