MySQL8默认加密使用的是caching_sha2_password插件,

root@devops_db 17:54:  [mysql]> show variables like 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
1 row in set (0.00 sec)

root@devops_db 17:55:  [mysql]>  select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | ice              | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

使用SQL客户端连接的时候就会报Plugin caching_sha2_password could not be loaded错误,常见有如下解决方法:
1、写入my.cnf文件后重启MySQL:

[mysqld]
default_authentication_plugin=mysql_native_password

2、兼容新老版本的认证方式:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxx' PASSWORD EXPIRE NEVER; #修改加密规则 
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxxx'; #更新用户密码 
FLUSH PRIVILEGES; #刷新权限

3、创建用户时指定加密方式:

CREATE USER 'ice'@'10.10.%' IDENTIFIED WITH mysql_native_password BY 'password'; #加密方式为
GRANT ALL privileges on TESTDB.* to 'ice'@'10.10.%' with grant option;
FLUSH PRIVILEGES;

使用mysql_native_password插件加密即可链接,mysql_native_password也是5.7以下版本使用的加密方式。

Tags标签: mysql8,caching_sha2_password,mysql_native_password Tags相关文章如下:

上一篇:CentOS7.8编译安装MySQL8.0.21

下一篇:ORA-00257报错处理