Java-MySQL Connection Error: Public Key Retrieval Not Allowed

├Źndice
  1. Overview
  2. Solution
  3. Conclusion

Overview

If you are encountering the error "Java-MySQL Connection Error: Public Key Retrieval Not Allowed", it means that your Java application is unable to connect to the MySQL database because the server's public key retrieval is not allowed. This error can occur when using Java versions 8u141 and later.

Solution

To resolve this error, you can add the "allowPublicKeyRetrieval=true" property to your JDBC connection string. This property enables public key retrieval and allows your Java application to connect to the MySQL database.

Here is an example of how to add this property to your JDBC connection string:


String url = "jdbc:mysql://localhost:3306/mydatabase?allowPublicKeyRetrieval=true";
Connection conn = DriverManager.getConnection(url, "username", "password");

Alternatively, you can also update your MySQL server configuration to allow public key retrieval by setting the "mysql_native_password" authentication plugin to use the "caching_sha2_password" plugin instead.

To do this, you can run the following SQL command:


ALTER USER 'username'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';

Note that you will need to replace 'username' and 'password' with your own credentials.

Conclusion

The "Java-MySQL Connection Error: Public Key Retrieval Not Allowed" can be caused by a security change in Java versions 8u141 and later. To resolve this error, you can add the "allowPublicKeyRetrieval=true" property to your JDBC connection string or update your MySQL server configuration. By following these steps, you can successfully connect your Java application to the MySQL database.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information