问题:MySQL8.0.14,创建普通用户账号后客户端远程连接报错:
Navicat客户端远程连接报错:1251 - Client does not support authentication protocol requested by server; consider upgrading MySQL client
CentOS主机上MySQL客户端连接报错:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
原因:MySQL8.0开始默认密码插件caching_sha2_password,旧的客户端上面没有这个插件,所以报错。
解决:解决问题的思路有两种,一是给客户端安装插件,二是修改MySQL账号使用native加密方式。
思路一:升级MySQL客户端到最新版本,支持MySQL8.0的插件。
思路二:这种思路有两种实现方法,一是给单独指定用户修改native加密方式,二是直接修改MySQL服务端配置文件,默认使用native加密方式。
1) 单独修改指定用户的plugin
mysql> select user,host,plugin,authentication_string from mysql.user where user = 'user1' \G
*************************** 1. row ***************************
user: user1
host: %
plugin: caching_sha2_password
authentication_string: 4im8KHnanNPJwRDVAItRhIE4h1hWv0hAcTBW1HH1mp0P&/G
mysql> ALTER USER 'user1'@'%' IDENTIFIED WITH 'mysql_native_password' BY '**************';
Query OK, 0 rows affected (0.02 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,plugin,authentication_string from mysql.user where user = 'user1' \G
*************************** 1. row ***************************
user: cindy
host: %
plugin: mysql_native_password
authentication_string: *8D9EF6E3AC0CD4EB7A1FF096D3141F60BFA6104F
1 row in set (0.00 sec)
mysql>
这种方式,需要针对指定的用户做配置修改,也可以在创建用户时指定native方式。
2) 修改MySQL服务端配置文件
#停止MySQL服务
[root@vm ~]# systemctl stop mysqld
#修改MySQL配置文件
[root@vm ~]# vi /etc/my.cnf
#打开下面这一行配置的注释
default-authentication-plugin=mysql_native_password
#启动MySQL服务
[root@vm ~]# systemctl start mysqld
这种方式修改了服务端默认配置以后,新创建的用户都默认使用native的验证方式,不需要在创建用户时指定native。