Jdbc串連MySQL 8時報錯“MySQLNonTransientConnectionException: Public Key Retrieval is not allowed”

來源:互聯網
上載者:User

標籤:driver   檔案中   exception   sha   cto   inux   為什麼   cat   hang   

一、問題

因停電檢修,今天重啟伺服器後,再啟動jboss就報錯“MySQLNonTransientConnectionException: Public Key Retrieval is not allowed”,jboss無法擷取對資料來源的JDBC串連。

二、解決過程

百度一下,先說是舊版JDBC驅動的bug,於是從maven中央庫下載最新的mysql-connector-8.0.11.jar,替換後修改jboss的modle說明、將設定檔中的driver-class改為‘com.mysql.cj.jdbc.Driver‘,但錯誤依舊。

繼續百度,說是需修改default_authentication_plugin設定,於是修改my.ini,增加[mysqld] default_authentication_plugin=mysql_native_password,重啟mysql 8,錯誤依舊。

繼續百度,說是仍需修改使用者的密碼加密方式,於是在mysql命令列執行:ALTER USER ‘myuser‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘mypassword‘;,這次雖仍報錯,但錯誤提示變成“InvalidConnectionAttributeException: The server time zone value ‘<亂碼>‘ is unrecognized or represents more than one time zone. ……”。

繼續百度,說是在jdbc串連串需指定time zone,於是修改jboss設定檔中的connection-url,在最後增加serverTimezone=Asia/Shanghai,重啟jboss,終於過關。

三、總結
  • 更換mysql的jdbc驅動,但其實從 5.1.37已經更新過這個bug,不一定非要用8.0.11;
  • 修改my.ini(Linux則是my.cnf),增加[mysqld] default_authentication_plugin=mysql_native_password;
  • 在mysql命令列執行:ALTER USER ‘myuser‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘mypassword‘;
  • 在jdbc串連串指定time zone。
四、疑問

問題雖然解決了,但仍存在幾個疑問:

  • 為什麼停電重啟前一切正常?
  • 為避免SSL,設定檔中的connection-url中加了useSSL=false,難道與這有關係?

Jdbc串連MySQL 8時報錯“MySQLNonTransientConnectionException: Public Key Retrieval is not allowed”

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.