centos7准备两台机器:192.168.131.101,192.168.131.102
mysql8安装
主节点:
创建一个账户专门用于同步主从数据,赋权限
CREATE USER 'slave'@'%' IDENTIFIED BY 'slave';
GRANT REPLICATION SLAVE ON *.* To 'slave'@'%' WITH GRANT OPTION;
flush privileges;
设置binlog和server id
vim /etc/my.cnf
log-bin=mysql-bin.log
server-id=101
重启mysqld
systemctl restart mysqld;
show master status;
File:mysql-bin.000001
Position:156
从节点:
设置binlog和server id
vim /etc/my.cnf
log-bin=mysql-bin.log
server-id=102
重启mysqld
systemctl restart mysqld;
启动slave
change master to master_host='192.168.131.101',master_user='slave',master_password='slave' ,MASTER_PORT=3306, master_log_file='mysql-bin.000001',master_log_pos=156;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
start slave;
显示slave状态
show slave status \G
错误一:
error connect to xxx cahche sha2 password:
解决:
主:
ALTER USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'slave' ;
FLUSH PRIVILEGES;
错误:
Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
vim /var/lib/mysql/auto.cnf 修改uuid
主要是因为机器是clone的导致uuid一样
参考资料
mysql8主从