MySQL8.0修改用户密码验证

问题:

MySQL升级到8.0,客户端或者连接器没有升级到8.0,连接时出现吧报错:

Authentication plugin 'caching_sha2_password' is not supported

查看当前用户信息:

mysql> select host,user,plugin,authentication_string,password_expired,password_last_changed,password_lifetime,account_locked,Create_role_priv,Drop_role_priv,Password_reuse_history,Password_reuse_time,Password_require_current FROM MYSQL.user whereuser='root'\G;
*************************** 1. row ***************************
                    Host: localhost
                    User: root
                  plugin: caching_sha2_password
   authentication_string: $A$005$3^3*[&!YiY\Ft]HlTE9I24QoS990EXKd3ANI.ePlavnWyt4fLyp7.Z1hh8
        password_expired: N
   password_last_changed: 2018-12-12 09:38:42
       password_lifetime: NULL
          account_locked: N
        Create_role_priv: Y
          Drop_role_priv: Y
  Password_reuse_history: NULL
     Password_reuse_time: NULL
Password_require_current: NULL
1 row in set (0.00 sec)

原因:

MySQL当前的身份验证插件不支持用户认证。

解决办法

身份验证不通过,修改身份验证信息:临时更改验证插件为mysql_native_password

mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'iris';
Query OK, 0 rows affected (1.85 sec)

重新连接数据库,可以正常登录。查看当前用户信息:

mysql> select host,user,plugin,authentication_string,password_expired,password_last_changed,password_lifetime,account_locked,Create_role_priv,Drop_role_priv,Password_reuse_history,Password_reuse_time,Password_require_current FROM MYSQL.user whereuser='root'\G;
*************************** 1. row ***************************
                    Host: localhost
                    User: root
                  plugin: mysql_native_password
   authentication_string: *72C26A280E81148FBC40D9D60BE74759464D93FA
        password_expired: N
   password_last_changed: 2018-12-12 09:27:04
       password_lifetime: NULL
          account_locked: N
        Create_role_priv: Y
          Drop_role_priv: Y
  Password_reuse_history: NULL
     Password_reuse_time: NULL
Password_require_current: NULL
1 row in set (0.00 sec)

原理:

查看当前用户身份验证插件

mysql>
mysql> SHOW VARIABLES LIKE 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
1 row in set, 1 warning (0.00 sec)
mysql>

以上设置是MySQL 8.0 默认的身份验证插件,caching_sha2_password和sha_password插件比mysql_native_password提供安全的身份验证技术,caching_sha2_password比sha_password性能更好,所以caching_sha2_password被选定为MySQL8.0首选&默认的用户身份验证插件。

如果使用默认的身份认证插件时当前的客户端活着连接器不支持8.0的默认身份认证插件,可以修改此参数

[mysqld]
default_authentication_plugin=mysql_native_password

由于此参数是只读参数,只能在配置文件中进行修改,并且需要重启生效

或者启动时带上--default_authentication_plugin参数。

如果后面升级了客户端或者连接器到可以支持MySQL8.0时,想更换身份认证插件,也可以使用一下命令修改

mysql> alter user 'root'@'localhost' identified with caching_sha2_password by 'iris';
Query OK, 0 rows affected (0.18 sec)
mysql>

或者永久修改

[mysqld]
default_authentication_plugin=caching_sha2_password

参考自:

https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值