两台服务器安装数据Mysql8.0(安装操作请查看Mysql8.0安装实战)
192.168.210.85 Mysql主
192.168.210.177 Mysql从
一、MySQL主从复制配置
1、mysql,开启二进制日志
2、在主服务器上授权,从服务器保存授权的信息
mysql> CREATE USER 'repl'@'192.168.210.177' IDENTIFIED by’123456’;
mysql> select user,host from mysql.user;
+------------------+-----------------+
| user | host |
+------------------+-----------------+
| repl | 192.168.210.177 |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------------+
5 rows in set (0.00 sec)
mysql> grant replication slave on *.* to 'repl'@'192.168.210.177';
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status;
3、Mysql从服务器
mysql> CHANGE MASTER TO
MASTER_HOST='192.168.210.85',
MASTER_USER='repl',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysql-bin.000003',
MASTER_LOG_POS=586;
mysql> start slave;
报错1在从库上操作:
(1)先停止从库
mysql> stop slave;
Query OK, 0 rows affected (0.02 sec)
(2)重新设置从节点的连接参数
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.210.85',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='123456',
-> MASTER_LOG_FILE='mysql-bin.000003',
-> MASTER_LOG_POS=586;
mysql> show slave status\G;
(3) mysql> start slave;
Query OK, 0 rows affected (0.04 sec)
4、验证主从同步:
(1)主服务器创建库
mysql> create database mzl;
Query OK, 1 row affected (0.00 sec)
(2)从服务器是否同步
验证完成主从同步正常
请 扫 描 关 注