• 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)
    

      

  • 相关阅读:
    TSQL编程的全局变量
    一、读大学,究竟读什么?
    受用一生的心理寓言
    字符串函数
    android wait notify实现线程挂起与恢复
    Java Thread.interrupt 中断JAVA线程
    android实现文件下载功能的3种方法
    Android startActivityForResult 和 setResult的使用
    Android 软键盘盖住输入框的问题
    Android蓝牙操作
  • 原文地址:https://www.cnblogs.com/Wtingting/p/14137458.html
Copyright © 2020-2023  润新知