6. 每一条修改数据的 query 都会记录到 master 的 binary log 中,slave 复制时
候 sql 线程会解析成合原来的 master 端执行过的相同的 query.
优点是:
不需记录每条变化,减少 log,节省 io。
缺点是:必须每条语句相关信息,即上下文信息。
Row level 级别 5.1 以后:
Binary log 会记录成每一行数据被修改的形式,然后在 slave 端口对相同的数
据进行修改。锁表操作会大量减少。
优点:不需记录执行 query 语句的上下文信息,只需要记录那条被修改了,修
改成什么了。
缺点是:产生的 log 记录比较大
还有一种不常用的 mixed 级别。
搭建过程
可以参考 mysql 官方文档:
步骤:
1 Creating a User for Replication
2 Setting the Replication Master Configuration
3 Setting the Replication Slave Configuration
4 Obtaining the Master Replication Information
5 Creating a Data Snapshot Using mysqldump
6 Creating a Data Snapshot Using Raw Data Files
7 Setting Up Replication with New Master and Slaves
8 Setting Up Replication with Existing Data
9 Introducing Additional Slaves to an Existing Replication Environment
10 Setting the Master Configuration on the Slave
导致 master 和 slave 不同步的原因
1 delete update 改变行的时候不用使用 limit 语句,没有 order by
2 一些函数在使用 statements based replication 时候如下: