Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to connect Mysql database with Java But I am facing following error Exception in thread “main” java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at in Python. So Here I am Explain to you all the possible solutions here.
Without wasting your time, Let’s start This Article to Solve This Error.
How This Error Occurs ?
I am trying to connect Mysql database with Java But I am facing following error.
Exception in thread “main” java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:108) at
How To Solve Exception in thread “main” java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at Error ?
- How To Solve Exception in thread “main” java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at Error ?
To Solve Exception in thread “main” java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at Error Just need to add client option to your mysql-connector
allowPublicKeyRetrieval=true
to allow the client to automatically request the public key from the server. and Also add useSSL=false. Just like this Example. jdbc:mysql://localhost:3306/db?allowPublicKeyRetrieval=true&useSSL=false. Now your error must be solved. - Exception in thread “main” java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at
To Solve Exception in thread “main” java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at Error Just need to add client option to your mysql-connector
allowPublicKeyRetrieval=true
to allow the client to automatically request the public key from the server. and Also add useSSL=false. Just like this Example. jdbc:mysql://localhost:3306/db?allowPublicKeyRetrieval=true&useSSL=false. Now your error must be solved.
Solution 1: Set allowPublicKeyRetrieval to true
Just need to add client option to your mysql-connector allowPublicKeyRetrieval=true
to allow the client to automatically request the public key from the server. and Also add useSSL=false. Just like this Example.
jdbc:mysql://localhost:3306/db?allowPublicKeyRetrieval=true&useSSL=false
Now your error must be solved.
Solution 2: Using DBeaver
If You are using DBeaver then just follow this setting.
- First of all Right click on your connection
- and choose “Edit Connection”
- On the “Connection settings” screen (main screen) click on “Edit Driver Settings”
- Click on “Connection properties”
- Right click the “user properties” area
- and choose “Add new property”
- Add two properties: “useSSL” and “allowPublicKeyRetrieval“
- Set their values to “false” and “true” by double clicking on the “value” column
Summary
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read