MySQLNonTransientConnectionException: Could not create connection to database server 解决办法

今天学习mybatis,遇到

MySQLNonTransientConnectionException: Could not create connection to database server无法创建数据库连接

第一步
网上查了一下,估计是mysql驱动包版本太低,我的mysql是8.0版本的,但是驱动依赖包却是5.1.29的。
在这里插入图片描述在这里插入图片描述于是把mysql连接驱动包升级到8.0.11版本。

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>8.0.11</version>
</dependency>

这时候有可能已经解决了问题了,如果还会出现如下错误中的其中一个,就进入第二步。

1、Loading class com.mysql.jdbc.Driver. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver.

或者

2、WARN: Establishing SSL connection without server's identity verification is not recommended
Error updating database. Cause: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

第二步
第 1 个错误是因为驱动类com.mysql.jdbc.Driver的已经废弃,现在应该用com.mysql.cj.jdbc.Driver,在数据库配置文件中修改一下即可。
在这里插入图片描述
代码 <property name="driver" value="com.mysql.cj.jdbc.Driver"/>

第 2 个错误需要添加SSL验证,或者是因为没有时域,可以将
?serverTimezone=GMT%2B8&amp;Unicode=true&amp;characterEncoding=utf-8&amp;useSSL=false
添加到数据库连接的后面,表示不适用SSL验证、数据集使用utf-8编码、使用东八区的时间。

完整代码如下
在这里插入图片描述

ps:在idea中,xml文件不可出现"&“符号,应该使用”&amp;"来代替(注意&amp后面有分号)。

修改完成后,数据库就可以正常连接啦。
  • 15
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
There are several reasons why you might be getting a MySQLNonTransientConnectionException when trying to connect to a database server: 1. Incorrect login credentials: One of the most common reasons for this error is incorrect login credentials. Make sure that you are using the correct username and password to connect to the database server. 2. Firewall or network issues: If your network or firewall is blocking the connection to the database server, you may get this error. Check with your network administrator to make sure that the necessary ports are open for MySQL connections. 3. Database server downtime: If the database server is down or undergoing maintenance, you won't be able to connect to it. Check with your database administrator to see if there are any issues with the server. 4. Insufficient permissions: Make sure that the user account you are using to connect to the database server has sufficient permissions to access the database. 5. Outdated drivers or software: If you are using outdated drivers or software to connect to the database server, you may get this error. Make sure that you are using the latest version of MySQL and the JDBC driver. To resolve this issue, you can try the following: 1. Double-check your login credentials, making sure that you are using the correct username and password. 2. Check with your network administrator to ensure that the necessary ports are open for MySQL connections. 3. Contact your database administrator to see if there are any issues with the database server. 4. Ensure that the user account you are using has sufficient permissions to access the database. 5. Update to the latest version of MySQL and the JDBC driver. If none of these solutions work, you may need to contact your IT department or a database administrator for further assistance.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值