連接 MySQL 報錯:2059 - authentication plugin 'caching_sha2_password' cannot be loaded...

問題

使用 Navicat 連接 MySQL 數據庫時,出現以下報錯提示:

2059 - authentication plugin 'caching_sha2_password' cannot be loaded...

這個報錯,中文意思就是:權限插件 caching_sha2_password 不能被加載

通過查閱 MySQL 的官方參考文檔,我們看到這樣的一段描述:

  • In MySQL 5.7, libmysqlclient uses as its default choice either mysql_native_password or the plugin specified through the MYSQL_DEFAULT_AUTH option for mysql_options().
  • When a 5.7 client tries to connect to an 8.0 server, the server specifies caching_sha2_password as its default authentication plugin, but the client still sends credential details per either mysql_native_password or whatever is specified through MYSQL_DEFAULT_AUTH.

從這里,我們就明白了:

  • 8.0 以前的默認身份驗證插件是 mysql_native_password
  • 8.0 以后的默認身份驗證插件是 caching_sha2_password

這里會報錯的原因在上面也提到了:5.7 的客戶端去連接 8.0 的服務端,因為默認的身份驗證插件不同,故會造成插件不能加載的錯誤

說明一下:目前大多數的 MySQL 客戶端都還沒有升級為 8.0 的認證方式,故像 Navicat、Sequel Pro、SQLyog 等這些常用的連接工具,都有可能出現這個問題

解決

將 MySQL 8.0 的身份認證插件改回為 mysql_native_password

  • 修改 身份認證插件為 mysql_native_password

    ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
    
  • 刷新權限

    FLUSH PRIVILEGES;
    

OK,現在再用 Navicat 去連接 MySQL 便可以成功了

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容