springboot连接mysql报错:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. ### The error may exist in file [D:\JavaProject\dataservice\target\classes\mybatis\mapper\ClassificationMapper.xml] ### The error may involve com.tjhnode.dataservice.mapper.ClassificationMapper.findAll ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
出现此错误以为是连接超时,百度答案大多是修改mysql的my.ini配置文件,设置wait_timeout时长,但是并没有解决问题。
经过分析,首先我猜想是application.yml中无法使用localhost访问,于是修改修改mysql允许ip地址访问
1.进入mysql命令行,输入select host,user from mysql.user;
发现所有host字段均为localhost;
2.设置允许被任意IP地址访问,执行 update mysql.user set host = '%' where user = 'root';
然后执行 flush privileges; 刷新MySQL的系统权限相关表,客户端工具使用ip测试连接成功
重新运行项目,访问依旧报错,经过百度猜想大概是mysql驱动配置问题
3.修改application.yml中数据库连接配置,将localhost换成ip,另外,url 需要添加时区设置:&serverTimezone=UTC,
我使用的mysql版本是8.0.17,而mysql6.0以上对应的驱动要使用 com.mysql.cj.jdbc.Driver
spring:
datasource:
# 数据源基本配置
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.135.1:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
type: com.alibaba.druid.pool.DruidDataSource
pom文件依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
重新运行,成功访问 http://localhost:8080/findAll,

springboot连接mysql报错:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException的更多相关文章
- 【small项目】MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link ...
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 数据库报错
-- 查询mysql 数据库链接空闲时间持有最大空闲时间,单位为秒 SHOW VARIABLES WHERE VAriable_name = 'interactive_timeout'; -- 会出现 ...
- mysql连接com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
现象:客户端连接服务器端mysql是没问题的,所有都木有问题,应用程序配置也没问题,但是连接就抛异常: com.mysql.jdbc.exceptions.jdbc4.CommunicationsEx ...
- Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决
感谢大佬:https://blog.csdn.net/a704397849/article/details/93797529 springboot + mybatis多数据库 + druid连接池配置 ...
- Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
很长的报错,截取 ERROR c.a.d.p.DruidDataSource - discard connection com.mysql.jdbc.exceptions.jdbc4.Comm ...
- mysql 5.1超过默认8小时空闲时间解决办法(错误:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure)
报错: MySQL第二天早上第一次连接超时报错, com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications lin ...
- 问题记录——com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
最近在搞一个Spring boot + Mybatis + Mysql的项目,用Mybatis访问数据库时,报了如下的错误,先在网上搜索了,试了各种办法都不行, 奇葩的是,连接另外1个数据库又没问题. ...
- mysql 数据库问题com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
本文转自:http://blog.csdn.net/zmzsoftware/article/details/6835604 MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc ...
- Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 78,050,512 milliseconds ago.
今天访问已经架上服务器的网站,报错: Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet s ...
- troubshooting-sqoop 导出 TiDB表数据报com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
2019-11-22 17:15:27,705 FATAL [IPC Server handler 13 on 44844] org.apache.hadoop.mapred.TaskAttemptL ...
随机推荐
- Bloxorz I (poj3322) (BFS)
[题目描述] It's a game about rolling a box to a specific position on a special plane. Precisely, the pla ...
- C# DataTable与实体的相互转换
using System; using System.Collections.Generic; using System.Data; using System.Reflection; namespac ...
- poj 2689 Prime Distance(区间筛选素数)
Prime Distance Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9944 Accepted: 2677 De ...
- .iml文件恢复
基于maven的java工程 执行 mvn idea:module可恢复.iml文件
- 【vue】vue不足 待补强
83719279 9:56:03尤其是路由 声明周期 父子通信 组件通信 以及钩子函数83719279 9:56:17这些我都不敢用,只能用最原始的方法83719279 9:56:32还有es6 js ...
- php 输出缓冲
<?php ob_start();//开启php输出缓冲区 echo "A"; //"A"会进入php输出缓冲区 ob_flush();//将php输出缓 ...
- 去除重复嵌套的html标签函数
去除重复嵌套的html标签 function strip_multi_tags($str, $tag = 'div'){ preg_match_all('/<'.$tag.'>|<\ ...
- js格式化数字或者小数,加入千分符(此次为”,“)
function npChangeNum(num) { var tag = (num || 0).toString().split("."); tag[0] = tag[0].re ...
- 信号量计算问题--n个进程, 共享3个资源, 当前信号量为-1, 其他进程继续执行P操作, 那么信号量应该继续减
选B
- B2C自营商城的订单设计方案
B2C自营商城的订单设计方案 2018年06月01日 17:19:00 lkx94 阅读数 1640 去年我们的美妆社区APP,上线了自有商城.之后经过多次版本迭代,商城系统的模块已经基本健全,值 ...