mysql8.0默认加密连接方式修改

mysql8.0开始,默认加密验证方式是“caching_sha2_password”。之前,mysql5.x的加密验证插件是“mysql_native_password”。
如果mysql版本从5.x升级到8.0以上,会一直报错,日志如下:

Plugin mysql_native_password reported: 'mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead

两种解决方法,一种是降级到mysql_native_password,一种是升级到caching_sha2_password。
caching_sha2_password比mysql_native_password更安全。

首先使用root账户登入mysql,查询所有数据库账户的的加密验证方式

select host,user,plugin,authentication_string from mysql.user;

可以在plugin看到所有数据库的加密验证方式。

一、mysql8.0加密验证方式caching_sha2_password,降级到mysql_native_password

更改数据库账户的验证方式为 mysql_native_password ,在mysql管理界面输入对应密码

ALTER USER '用户名'@'域' IDENTIFIED WITH mysql_native_password BY '密码' 

刷新配置,启用

FLUSH PRIVILEGES;

修改默认加密方式为 mysql_native_password 。
在mysql配置文件my.cnf,末尾增加一行代码。

default_authentication_plugin=mysql_native_password

并重启mysql

二、mysql5.x(旧的)数据库账户加密验证方式mysql_native_password,升级到caching_sha2_password

ALTER USER '用户名'@'域' IDENTIFIED WITH caching_sha2_password BY '密码';

刷新配置,启用

FLUSH PRIVILEGES;

修改默认加密方式为 caching_sha2_password 。修改mysql配置文件my.cnf。末尾增加一行代码。

default_authentication_plugin=caching_sha2_password

并重启mysql

MySQL自身的账户,可以通过以下SQL更新到caching_sha2_password模式:

UPDATE mysql.user SET plugin='caching_sha2_password' WHERE user='mysql.session' OR user='mysql.sys' OR user='mysql.infoschema';
UPDATE mysql.user SET authentication_string='$A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED' WHERE user='mysql.session' OR user='mysql.sys' OR user='mysql.infoschema';

发表评论

滚动至顶部