MySQL 5.5 主从双向同步

在Red Hat Enterprise Linux平台,利用MySQL主从同步原理,实现MySQL双向同步
MySQL版本:5.5.28
操作系统:RHEL 5.8 32bit

Server1:192.168.1.1
配置:my.cnf

  1. server-id = 1
  2. binlog-do-db = testdb
  3. binlog-ignore-db = mysql
  4. log-slave-updates
  5. replicate-do-db = testdb
  6. replicate-ignore-db = mysql

同步testdb数据库,这里不对mysql数据库进行同步
新增同步用户:

  1. grant replication slave on *.* to [email protected] identified by '123456';

启动Sever1;

  1. service mysql start

查看MySQL同步binlog文件名以及pos值:

  1. show master status;

MySQL 5.5 主从双向同步

Server2:192.168.1.2
配置:my.cnf

  1. server-id = 2
  2. binlog-do-db = testdb
  3. binlog-ignore-db = mysql
  4. log-slave-updates
  5. replicate-do-db = testdb
  6. replicate-ignore-db = mysql

与Sever1配置基本相同,只是server-id不同,而且不能相同,另外记得在[mysqld]配置区域里配置开启二进制日志记录:log-bin = mysql-bin
新增同步用户:

  1. grant replication slave on *.* to [email protected] identified by '123456';

启动Server2:

  1. service mysql start

配置同步:

  1. mysql>change master to master_host='192.168.1.1',
  2. mysql>master_user='slaveuser',
  3. mysql>master_password='123456',
  4. mysql>master_log_file='mysql-bin.000020',
  5. mysql>master_log_pos=107;
  6. mysql>slave start;
  7. mysql>show slave status\G;

相关推荐