mysql 8同步问题的解决方案

问题一、

主从复制报错2061:Authentication plugin ‘caching_sha2_password’ reported error:Authentication require secure connection

原因:在MySQL8.0之前,身份验证的插件是mysql_native_password,在MySQL 8.0中,caching_sha2_password 是默认的身份验证插件,安全性更高。在从库连接主库的时候使用的是不被 caching_sha2_password认可的RSA公钥,所以主库MySQL拒绝了数据库连接的请求,从而,从库报错’caching_sha2_password’ reported error:Authentication require secure connection。

官网给出的解决方案如下:

要从服务器请求RSA公钥,需要指定选项 –get-server-public-key

使用复制用户请求服务器公钥:

mysql -urepl -p'kR7EWsN&ChNr' -h 172.17.43.109 -P 3306 --get-server-public-key

在这种情况下,服务器将RSA公钥发送给客户端,后者使用它来加密密码并将结果返回给服务器。插件使用服务器端的RSA私钥解密密码,并根据密码是否正确来接受或拒绝连接。重新在从库配置change masrer to并且start slave,复制可以正常启动:

stop slave;
reset slave;
change master to master_user='repl',master_password='kR7EWsN&ChNr',master_host='172.17.43.109',master_port=3306,MASTER_LOG_FILE='binlog.000005', MASTER_LOG_POS=67980;
start slave;

问题二、

主从复制报错13117:Fatal error: The replica I/O thread stops because source and replica have equal MySQL server ids; these ids must be different for replication to work (or the –replicate-same-server-id option must be used on replica but this does not always make sense; please check the manual before using it).

原因:server_id冲突。

从库的my.cnf里面设置server_id=XX (区别与主库)

问题三、

主从复制报错13117:Fatal error: The replica I/O thread stops because source and replica have equal MySQL server UUIDs; these UUIDs must be different for replication to work.

原因:auto.cnf中UUID冲突。

进入从库数据库的datadir,

mv auto.cnf{,.bk}

重启数据库,自动生成一个新的auto.cnf。

Categories: 数据库运维