java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

应用访问数据库报错如下:java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

原因很简单,可能有两点:

1、你的数据库用户名和密码输入错了,会有这个报错(你可以自己试一下)。

2、mysql8.0后连接数据库的url变为了:

jdbc:mysql://localhost:3306/user?characterEncoding=utf8&******&serverTimezone=UTC&allowPublicKeyRetrieval=true

要在最后加上:&allowPublicKeyRetrieval=true