MYSQL数据同步,双向热备

  • A+
所属分类:Web开发 技术展台

测试环境,centos6.3

服务器1(CentOS6.3×32 Mysql5.5.18)
IP: 192.168.1.2
服务器2(CentOS6.3×64 Mysql5.5.18)
IP: 192.168.1.3

修改配置文件

修改 服务器2 上的/etc/my.cnf文件

server-id=2
重启mysql

service mysqld restart
启动

以下都是进入mysql后,执行的语句:

#服务器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;
于是,同步就搞定了!

下载服务恢复

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

Blue Captcha Image
Refresh

*