代码改变世界

【MySQL】Authentication plugin 'caching_sha2_password' reported error

2022-09-02 21:52  abce  阅读(1288)  评论(0编辑  收藏  举报

使用MySQL8.0.30创建主从,启动从库的时候报错:

Last_IO_Errno:2061
Last_IO_Error:error connecting to mater 'repl@xxxxx:3308' - retry-time:60 retries:1 massage:Authentication plugin 'caching_sha2_password' reported error:Authentication require secure connection.

 

原因是在MySQL8之前,身份验证插件默认是mysql_native_password;而从8.0开始,换成了caching_sha2_password。

 

1.可以在mysql server的配置文件中,继续使用旧的验证插件。在配置文件中即可。

[mysqld]
default_authentication_plugin=mysql_native_password

 

2.也可以在用户级别进行修改,修改用户使用的验证插件即可:

alter user '[username]'@'[host]' \
identified with mysql_native_password \
by '[password]';

 

3.也可以使用GET_MASTER_PUBLIC_KEY=1,请求公钥:

mysql> change master to master_host='xxxx', master_port=3308, master_user='repl', master_password='pwd',master_auto_position = 1,get_master_public_key=1;