MySQL出現The server requested authentication method unknown to the client [caching_sha2_password]不能登入?

posted in: MySQL 0

有些使用者在升級或是安裝新版本的MySQL之後,會發現無法登入(部分使用者會在使用一段時間才出現)

MySQL不能登入,出現The server requested authentication method unknown to the client [caching_sha2_password]該怎麼辦?

因為新版本MySQL,如MySQL8.0採用caching_sha2_password加密模式,而舊版本加密方式為mysql_native_password,

所以會出現這個無法相容的加密模式,部分MySQL設定則會在MySQL使用後一段時間才會出現這個問題。

解決的方法:

新建立用戶: CREATE USER 帳號名稱@localhost identified with mysql_native_password by '會員密碼';

原用戶問題修正:ALTER USER 帳號名稱@localhost identified with mysql_native_password by '會員密碼';

這樣就可以讓原本無法登入的帳號套用正確的加密模式,恢復登入。

當然部分的使用者會覺得MySQL8+採用caching_sha2_password加密模式會比傳統的mysql_native_password加密方式更安全,

如果需要維持8+的加密模式,就不需這道手續。