mysql8主从搭建

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主从

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值