centos 7 配置 mysql 5.7 主从复制

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

上一篇:XV Open Cup named after E.V. Pankratiev. GP of Tatarstan


下一篇:小学四则运算APP 第二阶段冲刺-第五天