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)
    

      

  • 相关阅读:
    巴洛克式和哥特式的区别
    推荐阅读书籍,是时候再行动起来了。
    AtCoder ABC 159F Knapsack for All Segments
    AtCoder ABC 159E Dividing Chocolate
    AtCoder ABC 158F Removing Robots
    AtCoder ABC 158E Divisible Substring
    AtCoder ABC 157F Yakiniku Optimization Problem
    AtCoder ABC 157E Simple String Queries
    AtCoder ABC 157D Friend Suggestions
    AtCoder ABC 156F Modularness
  • 原文地址:https://www.cnblogs.com/Wtingting/p/14137458.html
Copyright © 2011-2022 走看看