数据库之Public Key Retrieval is not allowed错误

数据库问题重现

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed

解决方式

1.mysql5及之前的版本使用的是旧版驱动”com.mysql.jdbc.Driver”,mysql6以及之后的版本需要更新到新版驱动,对应的Driver是”com.mysql.cj.jdbc.Driver”,但是这个驱动错误的信息是”Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.”,排除这个原因。

也就是升级Mysql

2.连接数据库的url中,加上_allowPublicKeyRetrieval=true_参数,经过验证解决该问题。

3.修改default_authentication_plugin设置,在my.ini中增加[mysqld]default_authentication_plugin=mysql_native_password,然后mysql命令行执行ALTER USER ‘username’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;最后在url中添加时区参数serverTimezone=Asia/Shanghai。

-------------本文结束感谢您的阅读-------------

本文标题:数据库之Public Key Retrieval is not allowed错误

文章作者:Jason

发布时间:2019年07月11日 - 00:07

最后更新:2019年07月11日 - 00:07

原始链接:https://jasonssun.github.io/2019/07/11/数据库之Public-Key-Retrieval-is-not-allowed错误/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。