- 实现原理
- 主库配置
- 1、开启二进制日志
- 2、创建远程连接账号,并赋予主从复制权限
- 从库配置
- 1、修改配置文件
- 2、配置同步
- 3、开启同步操作
- 3、查看同步状态
实现原理 主库配置
1、开启二进制日志需要关闭防火墙或开启3306端口!
默认关闭
开启二进制日志
vim /etc/my.cnf 添加如下: server_id=1 log_bin=binlog read_only=0 #1:只读,0:读写 重启mysql: systemctl restart mysqld
进入数据库,查询是否开启成功
show variables like '%log_bin%';2、创建远程连接账号,并赋予主从复制权限
//创建用户 create user 'tyron'@'%' identified with mysql_native_password by 'root@root'; //分配权限 grant replication slave on *.* to 'tyron'@'%';
相关报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 密码验证强度问题,可分为LOW -> MEDIUM -> STRONG,默认为MEDIUM
//修改密码验证强度 set global validate_password_policy=LOW;
File: 二进制写入文件名
Position: 当前位置
vim /etc/my.cnf 添加如下: server_id=2 read_only=1 #1:只读,0:读写 重启mysql: systemctl restart mysqld2、配置同步
8.0.23版本及以上: change replication source to source_host='xxx',source_user='xxx',source_password='xxx',source_log_file='xxx',source_log_pos='xxx'; 例:change replication source to source_host='192.168.118.133',source_user='tyron',source_password='root@root',source_log_file='binlog.000001',source_log_pos='154'; 8.0.23版本一下: change master to master_host='xxx',master_user='xxx',master_password='xxx',master_log_file='xxx',master_log_pos='xxx'; 例:change master to master_host='192.168.118.133',master_user='tyron',master_password='root@root',master_log_file='binlog.000001',master_log_pos='154';3、开启同步操作
start replica; //8.0.22之后 start slave; //8.0.22之前3、查看同步状态
show replica statusG; //8.0.22之后 show slave statusG; //8.0.22之前
相关错误:
Slave_IO_Running:NO 可能因为uuid相同,修改当前数据库uuid即可
vim auto.cnf
重启MySQL即可



