MySQLNonTransientConnectionException: Could not create connection to database server.

Spring整合mybatis并使用driud数据库连接池,启动测试类就报”MySQLNonTransientConnectionException: Could not create connection to database server.“,检查了一番配置文件没发现问题,而且我之前用过这些配置,按理说没问题。各种百度、谷歌没结果,想起来装了mysql 8.0,估计是这个问题。既然是这个问题,那么问题出在数据库连接驱动,看了下pom文件,发现用的是5.1.4版本,于是找了个8.0.11版本重新启动,果然报错就不一样了。

2018-05-26 16:52:53,928 [Druid-ConnectionPool-Create-1150963491] [com.alibaba.druid.pool.DruidDataSource]-[ERROR] create connection error
java.sql.SQLException: validateConnection false

另外在控制台上还打印了”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.“,意思是这个驱动类已经过时了,那只能说明MySQL 8.0使用的数据库连接字符串不一样。改完后重新启动搞定。

需要说明的是mysql 8.0版本还对时区有要求,否则启动提示”The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.“

有个别人的示例可以参考下:https://blog.csdn.net/beyond9305/article/details/80330125

贴一下连接字符串

url: jdbc:mysql://localhost:3306/yinliu?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true

driver: com.mysql.cj.jdbc.Driver

 

  • 37
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 25
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 25
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

养-乐多

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值