LoginSignup
53
41

More than 3 years have passed since last update.

SQL Error [08001]: Public Key Retrieval is not allowedの対処法 [JDBC:MySQL]

Last updated at Posted at 2019-07-14

ローカル環境
・データベース:MySQL 8.0.16
・言語:Java
・JDBCドライバ:mysql-connector-java-8.0.16
・DB参照ツール:DBeaver

DB接続しようとしたら、複数のエラーが発生

JavaからDB接続しようとしたところ、突如繋がらなくなった。
eclipseのコンソールでは下記のエラー記述が。

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet successfully received from the server was 25 milliseconds ago. 
The last packet sent successfully to the server was 28 milliseconds ago.

DBeaverからも接続を試みると、下記のエラー記述が。

SQL Error [08001]: Public Key Retrieval is not allowed

検索をかけて下記の記事を見て解決できました。
https://stackoverflow.com/questions/50379839/connection-java-mysql-public-key-retrieval-is-not-allowed

JDBCドライバのプロパティ「allowPublicKeyRetrieval」をtrue、「useSSL」をfalseにする

DBeaver:
1. 「データベースナビゲータ」の該当接続を右クリックし、「編集 Connection」を押す。
2. 「接続設定」 > 「ドライバのプロパティ」を選択。
3. 「allowPublicKeyRetrieval」をtrueに変更。
4. 「useSSL」をfalseに変更。(ちなみに自分は元々falseになっていたので対応不要だった)
5. 「OK」を押す。

Javaコード:
1. データベース接続文字列に「allowPublicKeyRetrieval=true&useSSL=false」を追加。
<記入例>

sample.java
String database = "jdbc:mysql://localhost:3306/sample_db?allowPublicKeyRetrieval=true&useSSL=false";
53
41
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
53
41