问题描述

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

问题分析

使用错误的MySQL驱动。

解决方案

更改JDBC的jar包

更改JDBC驱动名和连接字符串URL

// MySQL 8.0 以下版本 - JDBC 驱动名及数据库 URL
//static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
//static final String DB_URL = "jdbc:mysql://localhost:3306/xxxx";// MySQL 8.0 以上版本 - JDBC 驱动名及数据库 URL
//如果MySQL-connector-java用的6.0以上的,则driver要使用:com.mysql.cj.jdbc.Driver
//private static String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
//private static String DB_URL = "jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxxx?useSSL=false&serverTimezone=UTC";

注:

url 需要添加时区设置:

serverTimezone=GMT%2B8

(GMT%2B8代表东八区)

也可设置为:serverTimezone=UTC    serverTimezone=Shanghai(会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong)

如果未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求建立SSL连接。

为了符合当前不使用SSL连接的应用程序,verifyServerCertificate属性设置为’false’。

如果你不需要使用SSL连接,你需要通过设置useSSL=false来显式禁用SSL连接。

如果你需要用SSL连接,就要为服务器证书验证提供信任库,并设置useSSL=true

SSL – Secure Sockets Layer(安全套接层)

Maven

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

参考文章

https://www.cnblogs.com/xiaoyu666/p/10479636.html

https://www.cnblogs.com/wggj/p/9001899.html

JAVA——[MySQLNonTransientConnectionException:Could not create connection to database server.]解决方案相关推荐

  1. could not create connection to database server.] with root cause

    场景 SpringBoot项目运行后提示: 详细提示如下: ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: ...

  2. MySql :Could not create connection to database server.

    错误: Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:Error que ...

  3. JAVA.SQL.SQLNONTRANSIENTCONNECTIONEXCEPTION: COULD NOT CREATE CONNECTION TO DATABASE SERVER. ATTEMPT

    错误信息 java.sql.SQLNonTransientConnectionException: Could not create connection to database server. At ...

  4. nacos连接mysql出现:Could not create connection to database server. Attempted reconnect 3 times. Giving u

    nacos连接mysql出错 今天在学习nacos的时候,在从nacos内嵌数据derby切换到mysql的时候,出现一个错误,特意记一下. org.springframework.jdbc.Cann ...

  5. 数据库连接失败: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

    数据库连接失败信息摘要: ERROR-com.alibaba.druid.pool.DruidDataSource init:927: init datasource error,url: jdbc: ...

  6. Connection to @localhost failed. [08001] Could not create connection to database server. Attempt

    Connection to @localhost failed. [08001] Could not create connection to database server. Attempt 当我们 ...

  7. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.解决办法

    pycharm中database连接MySQL数据库时出现如下提示: [08001] Could not create connection to database server. Attempted ...

  8. [08001] Could not create connection to database server. Attempted reconnect 3 times.

    现象描述: 在JetBrains的系列产品中,database连接MySQL数据库时,如Idea.DataGrip.GoLand.Pycharm 等等,连接MySQL数据库时会出现如下提示: 连接失败 ...

  9. 08001] Could not create connection to database server. Attempted reconnect 3 times.

    现象描述: 在JetBrains的系列产品中,database连接MySQL数据库时,如Idea.DataGrip.GoLand.Pycharm 等等,连接MySQL数据库时会出现如下提示: 连接失败 ...

最新文章

  1. 了解Netflix-zuul网关服务
  2. 中兴c600olt数据配置_2698元起中兴天机Axon 11发布 轻薄设计视频双防抖
  3. Linux内核中大小端判定宏
  4. 记一次TCP连接异常故障解决
  5. python购物车实现的功能是什么_Python3实现购物车功能
  6. springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
  7. 外卖小哥是怎样炼成的?
  8. 很巧妙的进程防杀方法[秋镇菜原创]
  9. 七个你一定会犯的云安全错误
  10. f2fs学习笔记 - 4. f2fs文件系统组件说明
  11. ansys分析遇到的几个问题解决方案【文件保存】【网格划分】【steps controls】【应力应变动画】【力负载】【干涉】【part打散】【merge合并】【分析计算量】
  12. java基于springboot小说下载网站管理系统源码
  13. 程序化广告(2):程序化广告的参与者
  14. 3DLC系列:A/B 网格应用实践
  15. sql注入之万能密码总结
  16. 解决win10开机内存过高的办法(亲测有效)
  17. RHCSA操作第四次作业
  18. 购买虚拟服务器会计,购买云服务器在会计中怎么做账
  19. 计算机会计的专业知识,会计从业《会计电算化》基础知识:固定资产模块日常处理...
  20. 浙江大华前端一二三面经(2021届校招)

热门文章

  1. SQL Server 2005与2000写法上的差别
  2. 我的世界拿java开服务器_我的世界如何开服务器
  3. java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
  4. python函数体以冒号起始、并且是缩进格式的_Python基础第三课
  5. c语言程序中unit怎么定义,c ++中的一个定义规则(One definition rule in c++)
  6. java的imshow方法_如何在循环中使用子图,imshow或图形来显示所有图像?
  7. printf linux 头文件,Linux C 格式化输出时要注意的问题
  8. 六十六、实现Vue项目首页轮播图(vue-awesome-swiper)
  9. 第一行冻结_EXCEL函数tips(4) 数据冻结和查找
  10. 北京内推 | ​美团无人车团队招聘视觉算法实习生