Caused by: com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed solution
1. Background description
When the Java Spring Boot project starts, an error is reported when connecting to the database console:
Caused by: com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed
Two, the solution
The solution was found under a MySQL Forums on the MySQL official website . The solution is as follows:
Just add the following keyValue to spring.datasource.url.
allowPublicKeyRetrieval=true
As shown below:
3. Reason analysis
You can view the official documentation: MySqlConnector -> Connection Options -> Other Options
The translation is:
if the user uses sha256_password authentication, the password must be protected by the TLS protocol during transmission, but if the RSA public key is not available, the public key provided by the server can be used; the RSA public key of the server can be specified through ServerRSAPublicKeyFile in the connection, Or AllowPublicKeyRetrieval=True parameter to allow the client to obtain the public key from the server; but it should be noted that AllowPublicKeyRetrieval=True may cause malicious agents to obtain plaintext passwords through man-in-the-middle attacks (MITM), so it is disabled by default and must be explicitly enabled .
This article is over!