MySQL5.7 主主复制配置
MySQL 5.7 主主复制配置
一、简介:
MySQL主主复制其实就是两个MySQL主从复制组合到一起,接着我的上一篇博客《centos 7 配置 mysql 5.7 主从复制》配置即可。
二、配置主从复制
主库:192.168.12.3
从库:192.168.12.2
1. 主库从库所在服务器关闭防火墙
Systemctl stop firewalld
2. 主从库安装mysql 5.7
3. 修改主库/etc/my.cnf添加如下内容:
log-bin=mysql-bin
server-id=663
4. 重启主库mysql数据库
/etc/init.d/mysqld restart
5. 查看主库状态
show master status;
记录好File和Position,后面要用
6. 在主库上建立帐户
create user ‘repl’@’192.168.66.2’ identified by ‘mysql’;
7. 授权
grant replication slave on *.* to ‘repl’@’192.168.66.2’ identified by ‘mysql’;
8. 刷新权限
Flush privileges;
9. 修改从库/etc/my.cnf添加如下内容:
server-id=662
log-bin=mysql-bin
10. 重启从库mysql数据库
/etc/init.d/mysqld restart
11. 配置连接主服务器的信息:
mysql> stop slave;
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.66.3',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='mysql',
-> MASTER_PORT=3306,
-> MASTER_LOG_FILE='mysql-bin.000001',
-> MASTER_LOG_POS=154;
mysql> start slave;
12. 查看状态
Show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
三、配置主主复制
1. 查看192.168.66.2二进制日志名和位置
show master status;
记录好File和Position,后面要用
2. 在192.168.66.2建立用户
create user ‘repl3’@’192.168.66.3’ identified by ‘mysql’;
3. 授权
grant replication slave on *.* to ‘repl3’@’192.168.66.3’ identified by ‘mysql’;
4. 刷新权限
Flush privileges;
5.在192.168.66.3 配置连接主服务器的信息:
mysql> stop slave;
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.66.2',
-> MASTER_USER='repl3',
-> MASTER_PASSWORD='mysql',
-> MASTER_PORT=3306,
-> MASTER_LOG_FILE='mysql-bin.000001',
-> MASTER_LOG_POS=154;
mysql> start slave;
6、 在192.168.66.3查看状态
mysql>show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes