以下简单介绍的实现双方向同步两台mysql数据库的方法,不包括出现问题的解决方法:
条件
服务器1(CentOS6.0x32 Mysql5.5.18)
IP: 192.168.1.2
服务器2(CentOS6.0x64 Mysql5.5.18)
IP: 192.168.1.3
修改配置文件
修改 服务器2 上的/etc/my.cnf文件
server-id=2
重启mysql
service mysqld restart
启动
以下都是进入mysql后,执行的语句:站长教学网 eduyo.com
#服务器1 上执行
grant select,replication slave on *.* to 'sync'@'192.168.1.3' identified by 'your password';
flush privileges;
show master status;#记下File和Position的值 log1#服务器2 上执行
grant select,replication slave on *.* to 'sync'@'192.168.1.2' identified by 'your password';
flush privileges;
show master status;#记下File和Position的值 log2#服务器1 上执行(问号分别替换为刚才log2里面记下的两个值)
change master to master_host='192.168.1.3',master_user='sync', master_password='your password', master_log_file='?', master_log_pos=?;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
slave start;
show slave status;#服务器2 上执行(问号分别替换为刚才log1里面记下的两个值)
change master to master_host='192.168.1.2',master_user='sync', master_password='your password', master_log_file='?', master_log_pos=?;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
slave start;
show slave status;
于是,同步就搞定了!
(责任编辑:ken)