Chapter 19 Replication
Table of Contents
Status of this section: up to date 2009-10-21
This chapter describes MySQL replication principles, rules, and code, as it is supposed to work in version 5.1.
The MySQL replication feature allows a server - the master - to send all changes to another server - the slave - and the slave tries to apply all changes to keep up-to-date with the master. Replication works as follows:
-
Whenever the master's database is modified, the change is written to a file, the so-called binary log, or binlog. This is done by the client thread that executed the query that modified the database.
-
The master has a thread, called the dump thread, that continuously reads the master's binlog and sends it to the slave.
-
The slave has a thread, called the IO thread, that receives the binlog that the master's dump thread sent, and writes it to a file: the relay log.
-
The slave has another thread, called the SQL thread, that continuously reads the relay log and applies the changes to the slave server.
本节状态:最新2009-10-21
本章介绍了MySQL复制的原则,规则和代码。它应该用在5.1版本上。
MySQL的复制功能允许服务器- master -发送的所有更改到另一台服务器-的slave -和slave试图以应用所有更新操作,以便跟上最新的master。复制的工作原理如下:
-
每当master的数据库修改,更改写入到文件中,即所谓的二进制日志或binlog。这些内容是由客户端线程执行数据库查询(这里的查询是统称,实际上只会保留DML,select并不保存)的。
-
master上有一个线程,称为dump thread,即连续读取主的二进制日志,并将其发送到slave。
-
slave有一个线程,称为IO线程(IO thread),接收了master的dump thread发送的二进制日志,并将其写入文件:在 中继日志(relay log)。
-
slave上有另一个线程,称为 SQL线程(SQL thread),即连续读取中继日志并应用更改到slave的数据库上。