Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Reliable MySQL Using

Replication
Issac Goldstand
Mirimar Networks
www.mirimar.net
margol@beamartyr.net
What is replication?
• Allows 2 or more databases to maintain state
between them
• MySQL 3.23 and up supports asynchronous
replication
• One server acts as a master for one or more
slaves
• Slaves pull data to be replicated from server’s
binary logs and execute the relevant statements
locally
Replication basics…
Slave
Master Slave
Slave
Slaves

• One master supports multiple slaves


• Each node on the network is assigned a unique
identifying number
• Each slave attempts to connect to the master and
fetches data to be replicated
Replication basics…
Client Master Slave

DATA DATA
INSERT
INTO …

• Clients perform data modification on master


server
• INSERT, SELECT, DELETE, LOAD DATA
• EXECUTE in MySQL 5.0 and above
Replication basics…
Slave
Replication basics…

• Immediately following execution of command on master,


the command is written to the local binary log
Replication basics…

• Additionally, the master records its unique ID (to prevent


endless loops in circular replication scenarios) and the
timestamp for use with statements which use NOW(),
etc.
Replication basics…

• If the slave is online, the command is transmitted to the slave in


parallel (well, immediately following) to being written in the local
binary log
• Otherwise, when the slave next connects it will receive a list of all
pending statements from the master server’s binary log
Replication basics…

• The slave’s replication IO thread stores the command in the local


relay log
Replication basics…

• Once the data is received in the slave’s relay log, the


slave SQL thread executes the command locally,
bringing the slave up-to-date with the master
Replication basics…

• In MySQL 3.23, the IO and SQL threads were just one


thread. In later versions this was changed to boost
performance
• Load balancing – single write, distributed read
Client (INSERT) Master

Slave Slave Slave

Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT)

You might also like