因為使用docker 所以pull下來的mysql 版本是8.0版以後的
這個版本開始會使用sha256_password做為預設密碼 所以如果使用laravel會出現這個問題
php:PDOException::("PDO::__construct():The server requested authentication method unknown to the client[caching_sha2_password]")
用php沒辦法直接連結
所以
我的解法是去mysql下指令
ALTER USER 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
password跟jeffrey部分請自訂 localhost是連結來源(ip) 如果是要讓任何ip以jeffrey這個帳號連結mysql 請把localhost改成% 都要帶單引號喔!
如果是要創造新用戶 可以用
CREATE USER 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
另外 因為sequl pro 連結mysql8.0版以後的資料庫會出現一堆不明的錯誤,這是bug,sequl pro已經修好了
只要抓新版的sequl pro就可以了
P.S. php的下一個版本似乎已經有修理這個問題 接下來就等php的新版本發佈了!
https://github.com/php/php-src/commit/d6e81f0bfd0cb90586dd83d4fd47a4302605261a
參考資料:https://dev.mysql.com/doc/refman/8.0/en/alter-user.html