为了解决这个问题我四处奔波啊,百度了各种方法,最终发现是因为properties中属性赋值时等于号后面都加了引号。。。,引号去掉就好用了
官方mysql驱动下载地址
一
1. mysql版本
> 低版本的mysql用"com.mysql.jdbc.Driver"
高版本的mysql用"com.mysql.cj.jdbc.Driver"
**Driver首字母要大写**
但是我发现带不带“cj”,2020版本的idea还是会查出数据,只不过会给你爆出来提示
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2. mysql版本和驱动版本不一致问题
> 百度说有的mysql版本和mysql驱动版本差的太多也会报这个问题,但是我8.0版本的mysql配的5.1版本的驱动也没有问题,不过最好是驱动和mysql版本差不多
3. 配置文件内不能有空格
4. properties中属性值不要加引号
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatistest?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username=root
password=123456
二
改好后运行发现又出现了这个错误:Public Key Retrieval is not allowed
在properties中url的连接后面添加 allowPublicKeyRetrieval=true就可以啦
三
错误三:MySQLNonTransientConnectionException
mysql驱动版本与mysql数据库不一致(版本差异)
参考文章
Maven配置Mybatis项目异常:“java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver”解决办法
MYBATIS3 CANNOT FIND CLASS: COM.MYSQL.JDBC.DRIVER
在哪替换mysql驱动参考此链接
MySQL 8.0 Public Key Retrieval is not allowed 错误的解决方法
MySQLNonTransientConnectionException
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)