zoukankan      html  css  js  c++  java
  • php7.4连接MySQL8.0报错 PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")

    原因:
    mysql8默认的使用密码认证方式不一样,mysql8.0默认使用caching_sha2_password,但是之前版本都是使用mysql_native_password

    解决方案:
    将密码认证方式caching_sha2_password修改为mysql_native_password

    mysql> select user,host,plugin from mysql.user;
    +------------------+-----------+-----------------------+
    | user             | host      | plugin                |
    +------------------+-----------+-----------------------+
    | mysql.infoschema | localhost | caching_sha2_password |
    | mysql.session    | localhost | caching_sha2_password |
    | mysql.sys        | localhost | caching_sha2_password |
    | root             | localhost | caching_sha2_password |
    +------------------+-----------+-----------------------+
    4 rows in set (0.00 sec)
    

    修改root身份的"localhost"

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

    如果有root身份的"%"也改一下

    ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
    

    再次查看

    mysql> select user,host,plugin from mysql.user;
    +------------------+-----------+-----------------------+
    | user             | host      | plugin                |
    +------------------+-----------+-----------------------+
    | mysql.infoschema | localhost | caching_sha2_password |
    | mysql.session    | localhost | caching_sha2_password |
    | mysql.sys        | localhost | caching_sha2_password |
    | root             | localhost | mysql_native_password |
    +------------------+-----------+-----------------------+
    4 rows in set (0.09 sec)
    

      

  • 相关阅读:
    fishredux 大体流程
    flutter Container组件和Text组件
    vue 页面跳转以及传参
    mySql 查询当天、本周、最近7天、本月、最近30天的语句
    Flutter编译时下载依赖报错的解决方案
    计算属性和方法
    计算属性传参
    原生js发送请求
    MySQL数据库连接
    flask 蓝图
  • 原文地址:https://www.cnblogs.com/Wtingting/p/14137458.html
Copyright © 2011-2022 走看看