Mysql8.0 主从复制
Posted DevOps架构实战
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 statusG;
(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)从服务器是否同步
验证完成主从同步正常
请 扫 描 关 注
以上是关于Mysql8.0 主从复制的主要内容,如果未能解决你的问题,请参考以下文章