For easy MySQL failover, replication is a great solution. This post will cover the basics of performing a failover in case your master dies.
First, setup one-way replication (or two-way, but don't plan to use both servers for writes at the same time). Next, you'll want to direct all activity, or at least the writes, to the master. If the master dies, there are two major concerns:
- Redirecting the clients to the slave. There are several ways to handle this, such as Heartbeat or MySQL's JDBC driver.
-
Checking if the slave is caught up. This is trickier. If
the master's binary logs are still available, then you can do
SHOW SLAVE STATUS on the slave and compare the
READ_MASTER_LOG_POS to the master's binary log. For example, if
SHOW SLAVE STATUS shows:
Master_Log_File: localhost-bin.000051
…