MySqL的主--主复制
在上篇博文中介绍了MySqL的主--从复制过程。对于MySqL的主从复制,从服务器是不能有写操作的,这样从服务器的利用率就不高了,为了使其提高利用率,下来介绍MySqL的主—主复制过程。
从MySqL的主从复制过程可以知道要先在主服务器上的创建一个用户,为从服务器与主服务器用的,所以要在两个服务器上分别创建一个用户。
1、在两台服务器上各自建立一个具有复制权限的用户;
master: mysql> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO slave@'172.16.%.%' IDENTIFIED BY '123456';
slave: mysql> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO master@'172.16.%.%' IDENTIFIED BY '123456';
slave: mysql> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO master@'172.16.%.%' IDENTIFIED BY '123456';
2、修改配置文件;
在主服务器上修改如下所示的内容:
在主服务器上修改如下所示的内容:
[mysqld]
server-id = 10
log-bin = mysql-bin
replicate- do-db = magedu
auto-increment-increment = 2
auto-increment-offset = 1
server-id = 10
log-bin = mysql-bin
replicate- do-db = magedu
auto-increment-increment = 2
auto-increment-offset = 1
在从服务器上
[mysqld]
server-id = 20
log-bin =mysql-bin
replicate- do-db = magedu
auto-increment-increment = 2
auto-increment-offset = 2
server-id = 20
log-bin =mysql-bin
replicate- do-db = magedu
auto-increment-increment = 2
auto-increment-offset = 2
3、假定此时两台服务器均为新建立,且无其它写入操作,各服务器只需记录当前自己二进制日志文件及事件位置,以之作为另外的服务器复制起始位置即可
如下所示的内容:
master: mysql>SHOW MASTER STATUS\G
***********************1.row***********************
File: mysq-bin.000001
Position: 710
Binlog_Do_DB:
Binglo_Ignore_DB:
1 row in set (0.00 sec)
master: mysql>SHOW MASTER STATUS\G
File:mysql-bin.000003
Position: 811
***********************1.row***********************
File: mysq-bin.000001
Position: 710
Binlog_Do_DB:
Binglo_Ignore_DB:
1 row in set (0.00 sec)
master: mysql>SHOW MASTER STATUS\G
File:mysql-bin.000003
Position: 811
4、各服务器接下来指定另一台服务器为自己的主服务器即可:
master: mysql> CHANGE MASTER TO MASTER_HOST='172.16.35.2',MASTER_USER='master',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=811
slave: mysql> CHANGE MASTER TO MASTER_HOST='172.16.35.1',MASTER_USER='slave',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=710
slave: mysql> CHANGE MASTER TO MASTER_HOST='172.16.35.1',MASTER_USER='slave',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=710
这样主主复制就完成了。下面要做的就是测试了。
本文转自 ZhouLS 51CTO博客,原文链接:http://blog.51cto.com/zhou123/835363