Must Be
分类: Mysql/postgreSQL
2015-11-06 09:51:07
mysql版本:5.0.22
服务器A:192.168.1.111
服务器B:192.168.1.101
步骤:
1.在服务器A和服务器B均创建同步用户
grant replication slave,replication client on *.* to identified by '123456';
flush privileges;
2.在服务器A和服务器B修改my.cnf配置文件
服务器A:
server-id = 1
log-bin = mysql-bin
binlog-do-db = xxxx(需同步的数据库,多个可用逗号隔开)
binlog-ignore-db = information_schema(无需同步的数据库)
binlog-ignore-db = mysql
binlog-ignore-db = test
服务器B:
server-id = 2
log-bin = mysql-bin
binlog-do-db = xxxx
binlog-ignore-db = information_schema
binlog-ignore-db = mysql
binlog-ignore-db = test
3.重启mysql后,分别配置slave模式
服务器A:
在服务器B上运行:show master status\g;获得File和Position(比如mysql-bin.000009,98)
在服务器A上运行:
slave stop;
change master to master_host='192.168.1.101', master_user='repl', master_password='123456', master_log_file='mysql-bin.000009', master_log_pos=98;
slave start;
服务器B:
在服务器A上运行:show master status\g;获得File和Position(比如mysql-bin.000010,99)
在服务器B上运行:
slave stop;
change master to master_host='192.168.1.111', master_user='repl', master_password='123456', master_log_file='mysql-bin.000010', master_log_pos=99;
slave start;
4.测试