mysql 主主配置 master-master

一、进入第一台服务器(192.168.77.208)

1.修改/etc/my.cnf

[mysqld]

server-id=1

log-bin=mysql-bin

relay-log=relay-bin

replicate-do-db=bond,mysql

auto-increment-increment=2

auto-increment-offset=1

2.重启mysql

3.进入mysql console

mysql> grant reload,super,replication slave,replication client on *.* to kevin1@'192.168.77.199' identified by '123456';

mysql> flush privileges;

mysql> show master status;

记住: file和position的值

二、进入第二台服务器(192.168.77.199)

1.修改 /etc/my.cnf

[mysqld]

server-id=2

log-bin=mysql-bin

relay-log=relay-bin

replicate-do-db=bond,mysql

auto-increment-increment=2

auto-increment-offset=2

2.重启mysql

3.进入mysql console

mysql> grant reload,super,replication slave,replication client on *.* to kevin1@'192.168.77.208' identified by '123456';

mysql> flush privileges;

mysql>show master status;

记住: file 和position的值

mysql> change master to master_host='192.168.77.208',master_user='kevin1',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=381;

(两个值是第一台服务器读出来的)

mysql>start slave;

如果报错,可以执行:

stop slave;

reset slave;

三、进入第一台服务器

mysql> change mster to master_host='192.168.77.199' ,master_user='kevin1',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=383;

(两个值是第二台服务器读出来的)

mysql>start slave;

至此,配置完成,可以分别在两台服务器上测试下数据,看能不能同步到另一台上去。

猜你喜欢

转载自qingwei201314.iteye.com/blog/1878980