暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL8.0修改用户密码验证

小灯数据 2021-06-08
2814

问题:

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的默认身份认证插件,可以修改my.cnf的此参数
              [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




                  声明:本文首次发表在CSDN,详情请点击下方“阅读原文”

                  长按下图二维码,关注更多数据库实用技巧。



                  文章转载自小灯数据,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                  评论