📅  最后修改于: 2023-12-03 15:30:03.801000             🧑  作者: Mango
This is a common SQL exception that is thrown when attempting to establish a connection to a MySQL database.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed
This exception occurs when the connecting client (in this case, the JDBC driver) is not allowed to request the public key from the server to perform secure authentication. This restriction was introduced in MySQL 8.0.11.
There are multiple ways to resolve this issue:
default_authentication_plugin
setting in the MySQL configuration file.&allowPublicKeyRetrieval=true
to the connection string. For example:String url = "jdbc:mysql://localhost:3306/mydatabase?allowPublicKeyRetrieval=true";
Connection conn = DriverManager.getConnection(url, "username", "password");
In summary, the Public Key Retrieval not allowed SQL exception can be resolved by upgrading the JDBC driver, changing the MySQL server's authentication method, or modifying the JDBC connection string.