[JAVA] SQL Error [08001]: Workaround for Public Key Retrieval is not allowed [JDBC: MySQL]

Local environment -Database: MySQL 8.0.16 ・ Language: Java -JDBC driver: mysql-connector-java-8.0.16 -DB reference tool: DBeaver

Multiple errors occur when trying to connect to DB

When I tried to connect to DB from Java, it suddenly stopped working. The following error description is on the eclipse console.

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.

When I try to connect from DBeaver, the following error description appears.

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

I searched and saw the following article and was able to solve it. https://stackoverflow.com/questions/50379839/connection-java-mysql-public-key-retrieval-is-not-allowed

Set the JDBC driver property "allowPublicKeyRetrieval" to true and "useSSL" to false

DBeaver:

  1. Right-click the relevant connection in the Database Navigator and press Edit Connection.
  2. Select Connection Settings> Driver Properties.
  3. Changed "allowPublicKeyRetrieval" to true.
  4. Change "useSSL" to false. (By the way, I was originally false, so I didn't need to deal with it.)
  5. Press "OK".

Java code:

  1. Added "allowPublicKeyRetrieval = true & useSSL = false" to the database connection string.

sample.java


String database = "jdbc:mysql://localhost:3306/sample_db?allowPublicKeyRetrieval=true&useSSL=false";

Recommended Posts

SQL Error [08001]: Workaround for Public Key Retrieval is not allowed [JDBC: MySQL]
[Mysql2] Mysql2 :: Error: Specified key was too long; max key length is 767 bytes → Solved by creating a new file with character restrictions
SQL Error [08001]: Workaround for Public Key Retrieval is not allowed [JDBC: MySQL]
"tx" is not bound error