php7.3連接MySQL8.0報錯 PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]


報的錯誤:

In Connection.php line 664:

  SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = move and table_name = migrations and table_type = 'BASE TABLE')


In PDOConnection.php line 31:

  SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client


In PDOConnection.php line 27:

  SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client


In PDOConnection.php line 27:

  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

select user,host,plugin from mysql.user;

 

   

我這里執行了兩句修改,修改root身份的“localhost”和“%”,代碼如下:

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

  

 

 

執行成功:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM