码迷,mamicode.com
首页 > 数据库 > 详细

MySQL主主搭建

时间:2017-08-08 12:43:20      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:创建   ret   cat   bin   tty   property   auto   ble   机器   

1.在MySQL主从的基础上修改:

#master1上

[mysqld]

server-id=101

log-bin = mysql-bin

auto-increment-increment = 2

auto-increment-offset = 1000

#master2上

[mysqld]

server-id=103

log-bin = mysql-bin

auto-increment-increment = 2

auto-increment-offset = 1001

2、分别为俩台master创建各种的用户供对方使用

#master1的机器上
mysql> CREATE USER ‘master1‘@‘%‘ IDENTIFIED BY ‘123456‘;

#master2的机器上
mysql> CREATE USER ‘master2‘@‘%‘ IDENTIFIED BY ‘123456‘; 

3、分别给用户授予复制权限

#master1的机器上
mysql> GRANT REPLICATION SLAVE  ON *.* TO ‘master1‘@‘%‘ IDENTIFIED BY ‘123456‘;

#master2的机器上
mysql> GRANT REPLICATION SLAVE  ON *.* TO ‘master2‘@‘%‘ IDENTIFIED BY ‘123456‘;

4、分别重启服务,通过show master status 查看二进制文件名称还有pos位置,为slave配置复制位置

5.分别切换master,注意master_log_file还有master_log_pos

#master1的机器上

mysql> change master to master_host=‘192.168.137.103‘,master_user=‘master2‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000003‘,master_log_pos=951;

#master2的机器上

mysql> change master to master_host=‘192.168.137.101‘,master_user=‘master1‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000004‘,master_log_pos=698;

6.然后启动验证:

start slave

ok!!!!!!!

MySQL主主搭建

标签:创建   ret   cat   bin   tty   property   auto   ble   机器   

原文地址:http://www.cnblogs.com/Jt00/p/7305939.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!