解决Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 解决Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications

这个问题出现的原因是在数据库连接失败,从网上查了下,解决的方法五花八门,有改配置文件的,还有改代码的。但是每个人实质原因不同也会出现同样的错误。

1ecd1b2606ed46e9956a89f231c9802c.png

发了会呆,突然想明白,数据库连接不上,要么是url,要么是用户名或者密码。往后一翻,真正的原因找到了。。。

出错代码:

String url="jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true";
String username="root";
String password="123456";

把url后边的安全连接参数删除(有警告)或改成false【SQL版本大于connect版本,就要设置成false】:

String url="jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=false";
String username="root";
String password="123456";

就不报错了,能查询出来。

1ecd1b2606ed46e9956a89f231c9802c.png

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
6月前
|
关系型数据库 MySQL Linux
mysql登录报错Can't create a new thread
mysql登录报错Can't create a new thread
|
6月前
|
SQL 关系型数据库 MySQL
Mysql主从同步报错解决:Fatal error: The slave I/O thread stops because ..
Mysql主从同步报错解决:Fatal error: The slave I/O thread stops because ..
|
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就成功了。
146 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
220 0
|
关系型数据库 MySQL Java
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
213 0
|
安全 关系型数据库 MySQL
java程序启动连接mysql时报错com.mysql.jdbc.exceptions.jdbc4.CommunicationsExcepti:Communications link failur
java程序启动连接mysql时报错com.mysql.jdbc.exceptions.jdbc4.CommunicationsExcepti:Communications link failur
420 0
|
数据库连接 数据库 Java
解决:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure(真实有效)
数据库连接失败 在数据库连接失败,经常会有蛮多一系列的问题导致的原因,这个时候一定要多去尝试一下各种方法,并且做好自己的梳理! 一、例如我在SpringBoot项目中使用了阿里的数据库连接池Driud。
43148 0
|
Java 数据库连接 mybatis
mybatis:Exception in thread “main“ org.springframework.jdbc.UncategorizedSQLException
mybatis:Exception in thread “main“ org.springframework.jdbc.UncategorizedSQLException
161 0
mybatis:Exception in thread “main“ org.springframework.jdbc.UncategorizedSQLException
|
关系型数据库 MySQL 安全
MySQL中sync_relay_log选项对I/O thread的影响分析
MySQL中sync_relay_log选项对I/O thread的影响分析
3455 0