centos7配置mysql8.0主从复制

https://www.cnblogs.com/duanlinxiao/p/12091663.html

https://www.cnblogs.com/lanyangsh/p/10200418.html

 

注意:
1、主库:10.1.131.75,从库:10.1.131.76
2、server-id必须是纯数字,并且主从两个server-id在局域网内要唯一。

【主节点】
vi /etc/my.cnf
[mysqld]
log-bin=mysql-bin
server-id=2019001

重启服务
service mysqld restart

【从节点】
vi /etc/my.cnf
[mysqld]
server-id=2019002

重启服务
service mysqld restart

【主节点】
mysql> CREATE USER 'repl'@'10.1.131.76' IDENTIFIED WITH mysql_native_password BY 'XXXXXX';

mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.1.131.76';
mysql> flush privileges;

获取主节点当前binary log文件名和位置(position)
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 155 | | | |
+------------------+----------+--------------+------------------+-------------------+

【从节点】
mysql> CHANGE MASTER TO
MASTER_HOST='10.1.131.75',MASTER_USER='repl',MASTER_PASSWORD='XXXXXX',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=155;

开启主从同步
mysql> start slave;

再查看主从同步状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.1.131.75
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 155
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 322
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

注意看Slave_IO_Running和Slave_SQL_Running,必须都是YES,如果Slave_IO_Running是No,通常都是server-id配置有问题。

posted on 2021-01-22 08:01  四海骄阳  阅读(336)  评论(0编辑  收藏  举报

导航