Error "MySQLNonTransientConnectionException: Public Key Retrieval is not allowed" when Jdbc connects to MySQL 8

1. Problems

Due to a power outage for maintenance, after restarting the server today, and restarting jboss, the error "MySQLNonTransientConnectionException: Public Key Retrieval is not allowed" is reported, and jboss cannot obtain the JDBC connection to the data source.

Second, the solution process

Baidu, let's talk about the bug of the old version of JDBC driver, so download the latest mysql-connector-8.0.11.jar from the maven central library, and modify the modle description of jboss and driver-class='com.mysql in the configuration file after replacement. .cj.jdbc.Driver', but the error remains.

Continue to Baidu, saying that it is necessary to modify the default_authentication_plugin settings, so modify my.ini, add [mysqld] default_authentication_plugin=mysql_native_password, restart mysql 8, and the error remains.

Continue to Baidu, saying that it is still necessary to modify the user's password encryption method, so execute on the mysql command line: ALTER USER 'myuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';, although it still reports an error this time, the error prompt becomes "InvalidConnectionAttributeException: The server time zone value '<garbled>' is unrecognized or represents more than one time zone.  ".

Continue with Baidu, saying that the time zone needs to be specified in the jdbc connection string, so modify the connection-url in the jboss configuration file, add serverTimezone=Asia/Shanghai at the end, restart jboss, and finally pass the test.

3. Summary

  • Replace mysql's jdbc driver, but this bug has been updated since 5.1.37;
  • Modify my.ini (my.cnf for Linux) and add [mysqld] default_authentication_plugin=mysql_native_password;
  • Execute on the mysql command line: ALTER USER 'myuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';
  • Specify the time zone in the jdbc connection string.

4. Questions

Although the problem has been solved, there are still several questions:

  • Why did everything work fine before the power outage and restart?
  • To avoid SSL, useSSL=false is added to the connection-url in the configuration file. Does it have something to do with this?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325557733&siteId=291194637