When using MySQL 8.0 or later, you may encounter the following error:: Public Key Retrieval is not allowed
This is because MySQL 8.0 is enabled by defaultcaching_sha2_password
Plugins, while JDBC drivers do not allow retrieval of public keys by default. Here are some common solutions:
Solution 1: Modify the database connection string
Add in JDBC connection URLallowPublicKeyRetrieval=true
Parameters:
jdbc:mysql://localhost:3306/your_database?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
- allowPublicKeyRetrieval=true: Allows the search of public keys.
- useSSL=false: Disable SSL, depending on the requirements.
Solution 2: Modify the MySQL user authentication plug-in
ALTER USER 'your_user'@'your_host' IDENTIFIED WITH mysql_native_password BY 'your_password';
Solution Three: Update MySQL JDBC Driver
Make sure to use the latest version of MySQL JDBC driver to avoid incompatibility with MySQL 8.0 authentication methods
Maven example:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.30</version> </dependency>
Summarize
- If you do not want to modify the authentication plugin, use allowPublicKeyRetrieval=true to resolve the problem.
- You can modify the user authentication plug-in to mysql_native_password, or update the JDBC driver.
This is the article about: Public Key Retrieval is not allowed. For more related content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!