解决:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure(真实有效)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 数据库连接失败在数据库连接失败,经常会有蛮多一系列的问题导致的原因,这个时候一定要多去尝试一下各种方法,并且做好自己的梳理!一、例如我在SpringBoot项目中使用了阿里的数据库连接池Driud。

数据库连接失败

在数据库连接失败,经常会有蛮多一系列的问题导致的原因,这个时候一定要多去尝试一下各种方法,并且做好自己的梳理!


一、例如我在SpringBoot项目中使用了阿里的数据库连接池Driud。

有次在启动的时候,会报这样的错:

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet successfully received from the server was 319 milliseconds ago.  The last packet sent successfully to the server was 319 milliseconds ago.

就是数据库连接失败的问题。

二、定位问题

为什么会出现这样的一个问题呢?
出现这样的一个问题,首先确定是不是数据库问题,看看数据库能不能连上。
如果你的同事或者其他人都能够连上,那么数据库就没有问题。
看看你能不能上网。
如果你能上网,你的网络还OK。

三、代理问题

如果你使用了代理,就是哪种能帮助你上谷歌的软件。
你将它关掉,看看问题是否解决了。

四、增加一个配置

#下面这两个配置,可以在每次连接的时候判断一些连接是否有效
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.test-while-idle=true

OK,经过以上的一系列操作,问题基本上就能够解决了!

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
关系型数据库 MySQL 数据库连接
[已解决]踩过的坑之mysql连接报“Communications link failure”错误
[已解决]踩过的坑之mysql连接报“Communications link failure”错误
|
8月前
|
关系型数据库 MySQL Java
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
这个时候我们就要检查一下我们链接数据库的**url、root、password、**驱动是否正确,经过我的排查原来是我的url链接名不是localhost,真尴尬,改成localhost就成功了。
140 0
|
9月前
|
关系型数据库 MySQL Java
Mysql 报错:Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
Mysql 报错:Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
209 0
|
关系型数据库 MySQL Java
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
206 0
|
安全 关系型数据库 MySQL
java程序启动连接mysql时报错com.mysql.jdbc.exceptions.jdbc4.CommunicationsExcepti:Communications link failur
java程序启动连接mysql时报错com.mysql.jdbc.exceptions.jdbc4.CommunicationsExcepti:Communications link failur
419 0
|
SQL 安全 数据库连接
解决Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
解决Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
解决Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
|
Web App开发 Java 关系型数据库
【MySQL】com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago.
11390 0
|
Java 关系型数据库 Linux
解决Java程序连接mysql数据库出现CommunicationsException: Communications link failure错误的问题
一、背景   最近在家里捣鼓一个公司自己搭建的demo的时候,发现程序一启动就会出现CommunicationsException: Communications link failure错误,经过一番排查最后发现是数据库url写错造成的,这个过程中也对出现这个错误的解决思路有了一些自己的理解,现和大家分享。
3810 0