在Red Hat Enterprise Linux平臺,利用MySQL主從同步原理,實現MySQL雙向同步
MySQL版本:5.5.28
操作系統:RHEL 5.8 32bit
Server1:192.168.1.1
配置:my.cnf
-
server-id = 1
-
binlog-do-db = testdb
-
binlog-ignore-db = mysql
-
log-slave-updates
-
replicate-do-db = testdb
-
replicate-ignore-db = mysql
同步testdb數據庫,這里不對mysql數據庫進行同步
新增同步用戶:
-
grant replication slave on *.* to slaveuser@192.168.1.2 identified by '123456';
啟動Sever1;
-
service mysql start
查看MySQL同步binlog文件名以及pos值:
-
show master status;
Server2:192.168.1.2
配置:my.cnf
-
server-id = 2
-
binlog-do-db = testdb
-
binlog-ignore-db = mysql
-
log-slave-updates
-
replicate-do-db = testdb
-
replicate-ignore-db = mysql
與Sever1配置基本相同,只是server-id不同,而且不能相同,另外記得在[mysqld]配置區域里配置開啟二進制日志記錄:log-bin = mysql-bin
新增同步用戶:
-
grant replication slave on *.* to slaveuser@192.168.1.1 identified by '123456';
啟動Server2:
-
service mysql start
配置同步:
-
mysql>change master to master_host='192.168.1.1',
-
mysql>master_user='slaveuser',
-
mysql>master_password='123456',
-
mysql>master_port=3306,
-
mysql>master_log_file='mysql-bin.000020',
-
mysql>master_log_pos=107;
-
mysql>slave start;
-
mysql>show slave statusG;
|