Databases Reference
In-Depth Information
bandwidth than the more traditional statement-based replication. You can also
stop and start it at will. Thus, it's useful for maintaining a copy of your data in a
geographically distant location, such as a different data center. The distant replica
can even work with a connection that's intermittent (intentionally or otherwise).
However, if you want your replicas to have very low replication lag, you'll need a
stable, low-latency link.
Load balancing
MySQL replication can help you distribute read queries across several servers,
which works very well for read-intensive applications. You can do basic load
balancing with a few simple code changes. On a small scale, you can use simplistic
approaches such as hardcoded hostnames or round-robin DNS (which points a
single hostname to multiple IP addresses). You can also take more sophisticated
approaches. Standard load-balancing solutions, such as network load-balancing
products, can work well for distributing load among MySQL servers. The
Linux Virtual Server (LVS) project also works well. We cover load balancing in
Chapter 11 .
Backups
Replication is a valuable technique for helping with backups. However, a replica
is neither a backup nor a substitute for backups.
High availability and failover
Replication can help avoid making MySQL a single point of failure in your appli-
cation. A good failover system involving replication can help reduce downtime
significantly. We cover failover in Chapter 12 .
Testing MySQL upgrades
It's common practice to set up a replica with an upgraded MySQL version and use
it to ensure that your queries work as expected, before upgrading every instance.
How Replication Works
Before we get into the details of setting up replication, let's look at how MySQL actually
replicates data. At a high level, replication is a simple three-part process:
1. The master records changes to its data in its binary log. (These records are called
binary log events .)
2. The replica copies the master's binary log events to its relay log.
3. The replica replays the events in the relay log, applying the changes to its own data.
That's just the overview—each of those steps is quite complex. Figure 10-1 illustrates
replication in more detail.
The first part of the process is binary logging on the master (we'll show you how to set
this up a bit later). Just before each transaction that updates data completes on the
master, the master records the changes in its binary log. MySQL writes transactions
 
Search WWH ::




Custom Search