mysql5.5主主复制架构

mysql的主主复制

1、环境的准备2台服务器

   Server1: 192.168.0.11  系统为:redhat6.4 

   Server2:192.168.0.12  系统为:redhat6.4


设置主-主复制:

1、在两台服务器上各自建立一个具有复制权限的用户;

GRANT REPLICATION SLAVE ON *.* TO zzx'@'192.168.%.%' IDENTIFIED BY '123456';

FLUSH PRIVILEGES;

2、修改配置文件:
# 主服务器上
[mysqld]
server-id = 10
log-bin = mysql-bin
relay-log = relay-mysql
relay-log-index = relay-mysql.index
auto-increment-increment = 2
auto-increment-offset = 1


# 从服务器上
[mysqld]
server-id = 20
log-bin = mysql-bin
relay-log = relay-mysql
relay-log-index = relay-mysql.index
auto-increment-increment = 2
auto-increment-offset = 2


3、如果此时两台服务器均为新建立,且无其它写入操作,各服务器只需记录当前自己二进制日志文件及事件位置,以之作为另外的服务器复制起始位置即可


server1|mysql> SHOW MASTER STATUS\G
************************** 1. row ***************************
            File: mysql-bin.000001
        Position: 710
    Binlog_Do_DB: 
Binlog_Ignore_DB: 
1 row in set (0.00 sec)


server2|mysql> SHOW MASTER STATUS\G
mysql> SHOW MASTER STATUS\G
*************************** 1. row ***************************
            File: mysql-bin.000003
        Position: 811
    Binlog_Do_DB: 
Binlog_Ignore_DB: 
1 row in set (0.00 sec)


4、各服务器接下来指定对另一台服务器为自己的主服务器即可:
server1|mysql> CHANGE MASTER TO ...,MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=811


server2|mysql> CHANGE MASTER TO ...,MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=710


你可能感兴趣的:(mysql,主主复制)