MySQL主主搭建
Posted Jt00
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL主主搭建相关的知识,希望对你有一定的参考价值。
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主主搭建的主要内容,如果未能解决你的问题,请参考以下文章