MySQL Replication: Redundancy

Although performance is a much larger benefit of replication, it provides some redundancy for your application as well. Adding a slave server to a master allows you to perform read operations on either server, but you're still bound to the master server for writes. In a group of multiple slaves with one master, you have your data available and online in multiple locations, which means that certain servers can fall out of replication without a large disaster.

When disaster does occur, use the following recommendations as a guide.

If the master fails in a two-server replication environment, you will be dead in the water with regards to write queries. You will need to convert the slave into a master. This can be done relatively quickly by following these steps:

  1. Log into MySQL on the slave and run STOP SLAVE; RESET SLAVE;
  2. Add log-bin to the slave's /etc/my.cnf file and restart MySQL
  3. The slave server will now be running as a master
  4. Adjust your application to send reads and writes to the slave

Once the original master comes back online, set it up just like a new slave. You can skip some steps, such as setting the server-id, since that still should correspond to your overall configuration.

If the master fails in a multiple-server replication environment, you're still in bad shape for writes. Follow the steps shown above, and then adjust the other slaves (with CHANGE MASTER) so that they pull events from the new master instead.

If a slave fails in any replication environment, adjust your application so that it no longer attempts to send reads to the failed slave. While you work to bring the failed slave back online, your queries will be distributed to the remaining servers.

You can automate many of these operations by using applications like heartbeat, or by using load balancers to automatically route database traffic.

Printed from: http://rackerhacker.com/2008/01/03/mysql-replication-redundancy/ .
© Major Hayden 2012.

1 Comment   »

  • Patrick says:

    Hi,
    exactly the information Iwas looking for.

    i'm wondering if I dont want to setup the original master(lets call A) as a slave, what would be the procedure to change the new master back to the slave(lets call B) once the original master can be recovered. I guess we are assuming the new master has been in use for a few days and has new data, and either the original master has no data or data in state from few days ago.
    Does the following sound correct?

    1) do a flush table with read lock on B
    2) do a mysqldump on B and load into A. Now data should be same on A and B.
    3) show master status on A to record binlog file and position
    4) use CHANGE MASTER to on B to update new position and binlog.
    5) START SLAVE on B.

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this