mysql 8.0 修改了默认的加密的插件方式,8.0之前默认mysql_native_password,8.0中默认值为sha256_password,需要配置密钥
[mysqld] sha256_password_private_key_path=/usr/local/mysql/myprivkey.pem sha256_password_public_key_path=/usr/local/mysql/mypubkey.pem
如果用户使用了 sha256_password 认证,密码在传输过程中必须使用 TLS 协议保护,但是如果 RSA 公钥不可用,就出现此异常。
解决方法:可以使用服务器提供的公钥;可以在连接中通过 ServerRSAPublicKeyFile 指定服务器的 RSA公钥,或者AllowPublicKeyRetrieval=True参数以允许客户端从服务器获取公钥;但是需要注意的是 AllowPublicKeyRetrieval=True可能会导致恶意的代理通过中间人攻击(MITM)获取到明文密码,所以 默认是关闭的,必须显式开启
创建一个使用mysql_native_password加密的用户
mysql> CREATE USER root@'%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.05 sec) mysql> mysql> GRANT ALL ON *.* TO 'root'@'%'; Query OK, 0 rows affected (0.02 sec) mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; Query OK, 0 rows affected (0.05 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec)
可在配置文件设置默认的用户身份验证插件。
[mysqld] default_authentication_plugin=mysql_native_password
相关资料:
https://github.com/xiaoboluo768/qianjinliangfang/wiki/default_authentication_plugin
设置默认的用户身份验证插件。
有效值为:
mysql_native_password:使用mysql native认证插件,详情参考链接:https://dev.mysql.com/doc/refman/5.7/en/native-pluggable-authentication.htm
sha256_password:使用SHA-256认证插件,详情参考链接:https://dev.mysql.com/doc/refman/5.7/en/sha256-pluggable-authentication.html
注意:如果此变量的值不是mysql_native_password,因为MySQL 5.5.7之前的mysql客户端不支持mysql_native_password身份验证协议之外的协议,所以这个时候mysql客户端无法连接到server
default_authentication_plugin值影响如下:
CREATE USER或GRANT语句创建用户时,如果未明确指定用户认证插件,则默认使用该变量指定的值
old_passwords系统变量会影响使用mysql_native_password或sha256_password身份验证插件的帐户的密码哈希值。old_passwords会根据default_authentication_plugin设置的不同认证插件来调整密码哈希方法所需的值
如果客户端成功连接到Server,且使用了与服务端不同的密码认证插件,则在执行CREATE USER和GRANT语句创建用户并设置密码时会报错,可以使用–default-authentication-plugin命令行选项指定与server相同的密码认证插件
全局变量,只读变量,枚举类型,默认值为mysql_native_password(8.0中默认值为sha256_password),有效值为:mysql_native_password、sha256_password,MySQL 5.7.2版本引入



