Mysql 5.1 配置双主

  
双主的配置,其实就是做两次主从,主要是解决双主自增 id 不能重复的问题,用 auto-increment-increment 和 auto-increment-offset 来避免出现混乱。

auto-increment-increment 写主Master机器的数量,aotu-increment-offset 是默认的开始值,如果是 4 太机器做主,
auto-increment-increment = 4
aotu-increment-offset 后面的值,四个机器分别是 1 2 3 4,就能避开重复。
mysql 5.1 安装步骤参考 5.1 主从


环境说明:两台机器 ,centos 6.5,mysql 5.1
第一台机器:hostname: centos2      ip: 192.168.32.142
第二台机器:hostname: centos3      ip: 192.168.32.143

Centos 2  配置文件
# vim /etc/my.cnf
server-id       = 1
log-bin=mysql-bin
auto-increment-increment=2
auto-increment-offset=1
log-slave-updates
auto-increment 两行的配置,使 centos 2 字段产生的数值是 奇数1,3,5,7
下面的centos 3 产生的是 2,4,6,8 等,这样会避开双主 id 重复的问题。
mysql> grant replication slave on *.* to 'user143'@'192.168.32.143' identified by 'user143';
mysql> flush privileges;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      350 |              |                  |
+------------------+----------+--------------+------------------+



Centos 3 配置文件
server-id       = 101
log-bin=mysql-bin
auto-increment-increment=2
auto-increment-offset=2
log-slave-updates


mysql> grant replication slave on *.* to 'user142'@'192.168.32.142' identified by 'user142';
mysql> flush privileges;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      350 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.01 sec)




Centos 2 SQL 授权
mysql> change master to master_host='192.168.32.143', master_user='user142', master_password='user142',master_log_file='mysql-bin.000001', master_log_pos=350;
Query OK, 0 rows affected (0.10 sec)


Centos 3 授权
> change master to
master_host='192.168.32.142',
master_user='user143',
master_password='user143',
master_log_file='master-bin.000001',
master_log_pos=350;

Query OK, 0 rows affected (0.13 sec)


                                                                                                             


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值