mysql之主主配置_mysql 主主配置

mysql主主备份同步,其实就是互相主从,A对B主从,B对A主从

配置起来与mysql 主从差不多,只是有点小地方需要改动一下

注:在实验之前请先关闭iptables和selinux ,iptables -F && service iptables save

vim /etc/selinux/config 中selinux值改成disabled

环境描述:A:192.168.3.116

B:192.168.3.251

给ABmysql设置登录密码,命令:mysqladmin -uroot password 'yourpass'

各登录ABmysql

A:grant replication slave,file on *.* to 'repl'@'192.168.3.251' identified by '123456';

flush privileges;

B: grant replication slave,file on *.* to 'repl'@'192.168.3.116' identified by '123456';

flush privileges;

配置各mysql配置文件

A:

vim /etc/my.cnf

在server-id出修改并添加如下语句

server-id       = 1

binlog-do-db=test

binlog-ignore-db=mysql

replicate-do-db=test

replicate-ignore-db=mysql

log-slave-updates

sync_binlog=1

auto_increment_increment=2

auto_increment_offset=1

B:

server-id       = 2

binlog-do-db=test

binlog-ignore-db=mysql

replicate-do-db=test

replicate-ignore-db=mysql

log-slave-updates

sync_binlog=1

auto_increment_increment=2

auto_increment_offset=2

其中:log-slave-updates    将执行的复制sql记录到二进制日志

sync_binlog  当有二进制日志写入binlog文件的时候,mysql服务器将它同步到磁盘上

auto_increment_increment,auto_increment_offset 主要用于主主复制中,用来控制AUTO_INCREMENT列的操作

重启ABmysql服务,并进入MySQL数据库

A:flush tables with read lock;

show master status;查看此时A的master_log_file 和master_log_pos值

unlock tables;

slave stop;

change master to master_host='192.168.3.251',master_user='repl',master_password='123456',master_log_file='mysql-bin.000004',master_log_pos=106;#此处的master_log_file和master_log_pos为B上show master status值

start slave;

B:

flush tables with read lock;

show master status;查看此时B的master_log_file 和master_log_pos值

unlock tables;

slave stop;

change master to master_host='192.168.3.116',master_user='repl',master_password='123456',master_log_file='mysql-bin.000004',master_log_pos=106;#此处的master_log_file和master_log_pos为A上show master status值

start slave;

查看状态,在A和B上分别show slave status;若同时出现

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

则表示互为主从配置成功;

测试:针对同步的数据库test操作,分别在A上create table tb1 ,在B上show tables;若出现A上创建的tb1则表示A到B同步成功;在B上create table tb2,A上show tables;出现tb2,则表示B到A同步成功;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值