文章目录
一、测试环境准备
节点1 | 节点2 | |
---|---|---|
IP地址 | 192.168.101.77 | 192.168.101.79 |
MySQL版本 | 8.0.32 | 8.0.32 |
二、主从搭建
1.创建复制用户
节点1执行:
mysql> CREATE USER 'repl'@'%' IDENTIFIED BY '123123';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
mysql> FLUSH PRIVILEGES;
mysql> show master status;
2.创建复制关系
节点2执行
mysql>
change master to
master_host='192.168.101.77',
MASTER_PORT=3306,
master_user='repl',
master_password='123123' ,
MASTER_AUTO_POSITION=1;
3.开启复制,确认复制是否成功
开启复制
mysql> start slave;
查看复制状态(下面是正常状态)
root@localhost:(none)>show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 192.168.101.77
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 197
Relay_Log_File