How to resolve “java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed” error in java

If you are connecting to MySQL version 8 from your java application, there are bright chances that you might have come across the following error

java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

and if you are accessing a MySQL database from a web or application server such as Wildfly or Tomcat, then you would have encountered this error

java.sql.SQLException: Cannot create PoolableConnectionFactory (Public Key Retrieval is not allowed)

Add allowPublicKeyRetrieval connection option of MySQL with a value of true to the JDBC connection string. Thus, your connection string should be modified as

jdbc:mysql://<database server ip>:3306/databaseName?allowPublicKeyRetrieval=true

Since you are connecting to a database, you will be using password authentication. Obviously, the password should be protected while transmitting over the network. By default Transport Layer Security(TLS) is used but if it cannot be used, then RSA public key encryption is used.

In order for the client to request for the public key from the database server, allowPublicKeyRetrieval option is used. But remember, using this option could expose the password to malicious attacks. That is why, this option is set to false by default.


Share your thoughts !!

Close Menu

Never Miss an article !

Get the new post delivered straight into your inbox, enter your email and hit the button

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

codippa will use the information you provide on this form to be in touch with you and to provide updates and marketing.