PHP 無法連線 MySQL 8?停用 caching_sha2_password 作為臨時解決方案

發表日期:
2020.02.23
/
分類:
Dev
這幾天嘗試使用 MySQL 8 來作為開發用的資料庫,結果發現我的 PHP 無法連線上資料庫,連帶著 phpMyAdmin 也無法使用。 我看到的錯誤訊息是這樣的: mysqli::real_connect(): (HY000/2054): The server requested authentication method unknown to the client

這幾天嘗試使用 MySQL 8 來作為開發用的資料庫,結果發現我的 PHP 無法連線上資料庫,連帶著 phpMyAdmin 也無法使用。

我看到的錯誤訊息是這樣的:

mysqli::real_connect(): (HY000/2054): The server requested authentication method unknown to the client

調查過後了解是 MySQL 8 正式導入 caching_sha2_password 作為驗證機制,目前 PHP 7.4 版已能夠支援。

只不過因為目前要將這個伺服器架構作為軟體開發用,所以就使用暴力解,停用 caching_sha2_password,修改回 mysql_native_password。

操作紀錄

開啟 MySQL 設定檔 (my.cnf 或 my.ini),修改 default_authentication_plugin 欄位值為 mysql_native_password。

原先的設置

default_authentication_plugin=caching_sha2_password

修改後

default_authentication_plugin=mysql_native_password

之後將使用者的密碼驗證方式修改為 MySQL Native Password 就可以連線了 (MySQL Workbench 是顯示 Standard)。

只不過停用 caching_sha2_password 應該也不是長久之計,當到正式部署時再來寫他的設置筆記。

comments powered by Disqus