一、从服务启动复制进程,连接主服务,报错:
Error connecting to source 'cpdatabase@xxxIP:3308'. This was attempt 4/86400, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
解决:
1、修改复制用户的认证插件,简单有效(推荐)
# 更新身份验证插件为(mysql_native_password)
alter user 'cpdatabase'@'从服务ip' identified with mysql_native_password by 'test1234';
# 刷新表
flush privileges;
2、连接时,显示使用 ssl 安全连接
mysql -h xxxIP -P 3308 -u root -p --ssl-mode=REQUIRED
或
jdbc:mysql://xxxIP:3308/dbname?useSSL=true&requireSSL=true
3、配置主服务器,修改my.cnf文件,允许非 SSL 连接(关闭安全连接)
[mysqld]
require_secure_transport = OFF # 关闭强制 SSL
二、重复数据导致复制报错而中断,可能报错:
Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction 'ANONYMOUS' at source log mysql-bin.000009, end_log_pos 11862. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
也可以查看性能表报错信息:
SELECT * FROM performance_schema.replication_applier_status_by_worker WHERE WORKER_ID = 1\G;
解决:
1、忽略二进制复制位置,从最新位置开始读取
# 停止复制
stop slave;
# 使从服务忘记其在主服务二进制日志中的复制位置
reset slave;
# 关闭GTID自动定位(如果未启动GTID自动定位,可忽略此步)
change master to master_auto_position=0;
# 更改链路信息为主服务二进制当前位置开始读取
change master to master_log_file='mysql-bin.XXX', master_log_pos=XXX;
# 启动复制
start slave;
2、配置默认跳过相关错误导致赋值中断(协调器停止工作)
# 从库 my.cnf 配置添加
[mysqld]
slave-skip-errors = 1062
# 重启mysql
service mysql restart
或
docker restart mysql
说明:
1062:主键重复冲突
1053:锁超时错误
1007:创建数据库,数据库已经存在
slave-skip-errors 的取值可查看 Last_SQL_Errno 的值,与之对应。示例:slave-skip-errors = 1062,1007
3、启用 GTID 复制,避免依赖 binlog 文件名和位置
【1】分别在主从服务的 my.cnf 配置添加
[mysqld]
gtid-mode = ON
enforce-gtid-consistency = ON
备注: ON-开、OFF-开
【2】分别重启mysql服务后,在从服务更新主从链路信息(启用 GTID 自动定位)
# 停止复制
stop slave;
# 启动GTID自动定位
change master to master_auto_position=1;
# 启动复制
start slave;
说明:
【1】master_auto_position 对应的值:1-开、0-关
【2】master_auto_position 启动GTID自动定位,如果处于1启动状态则主从链路无法设置(master_log_file、master_log_pos)等信息