当前位置:网站首页>【报错】Root Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
【报错】Root Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
2022-08-09 06:52:00 【爱干饭的猿】
目录
【大家好,我是爱干饭的猿,如果喜欢这篇文章,点个赞,关注一下吧,后续会持续分享每日一题和SSM其他重要知识点总结】
上一篇文章:《【web】理解 Cookie 和 Session 机制》
用 Linux 部署 web 项目的测试过程中遇到了这个错误。
🧨1. 报错情况一:
根据提示:
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
从上次成功发送到服务器的数据包是0毫秒前。驱动程序尚未从服务器收到任何数据包。
说明这个数据库是远程连接的爆出这个错误的,原因是 mysql 数据库远程连接中断设定的默认查询执行失败。
分析原因:检查自己本地数据库连接是否正确
解决方案:1. 检查配置:检查在xml中对mysql配置的jdbc。
2. 检查路径:jdbc 连接 mysql 时的url 书写是否正确。
3. 检查端口:一般端口没啥问题。
4. 检查 mariadb 是否启动。(我就是没设置开机自启动,导致不能正确连接)
1.1 检查配置
url: jdbc:mysql://127.0.0.1:3306/数据库名称?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
1.2 检查路径
1.3 检查端口
1.4 检查 mariadb 是否启动
打开 Xshell 7 连接到自己的云服务器
mysql -uroot -p 连接数据库
发现报错:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
找到原因:可能是 mariabd (mysql) 未启动
systemctl start maridb 启动mariadb
ps aux | grep mariadb 检查进程
确实是 mariabd (mysql) 未启动导致。
扩展:
- systemctl start mariadb 启动
- systemctl stop mariadb 关闭
- systemctl enable mariadb 设置开机自启
再次连接mysql。
mysql -uroot -p 连接数据库
连接数据库成功。
访问部署好的网站:
访问成功,报错解决成功。
🧨2. 报错情况二:
根据提示:
The last packet successfully received from the server was 1,302 milliseconds ago
从服务器成功接收到的最后一个数据包是1302毫秒前。
2.1 检查配置
解决方法如下:
- 修改数据库连接配置在数据库连接上,加“&autoReconnect=true&failOverReadOnly=false”配置,但是mysql4以下的版本有效,mysql5以上的无效。
- 修改数据库连接有效时间,在数据库配置上设置,把数据库连接有效时间设置长一点,比如设置12小时或者24小时。**方法:**在MySql的配置文件my.ini或者mysql.xml的配置文件里边加上interactive_timeout=388000和wait_timeout=388000即可!
第一个问题的错误,需要把数据库连接配置德的useSSL=true改成useSSL=false
MySQL在高版本需要指明是否进行SSL连接。
- true 需要连接
- false 不需要连接
使用JDBC跟你的数据库连接的时候,你的JDBC版本与MySQL版本不兼容,MySQL的版本更高一些,在连接语句后加上“useSSL=‘true’” ,就可以连接到数据库了。
本次分享就到这里,如果你喜欢这篇文章,请点赞加关注吧,或者如果你对文章有什么困惑,可以私信我。
边栏推荐
- e-learning summary
- 单例 DCL(double check lock) 饱汉模式和饿汉模式
- Example of using the cut command
- Mysql实操
- 按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
- 错误:为 repo ‘oracle_linux_repo‘ 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.
- 字节也开始缩招了...
- flask创建数据库失败未报错
- 【ROS2原理8】节点到参与者的重映射
- mysql summary
猜你喜欢
字节跳动面试题之镜像二叉树2020
Altium designer software commonly used the most complete package library, including schematic library, PCB library and 3D model library
leetcode 之盛水问题
网络学习总结
变压器的工作原理(图解,原理图讲解,一看就懂)
Error jinja2.exceptions.UndefinedError: 'form' is undefined
XILINX K7 FPGA+RK3399 PCIE驱动调试
Fragments
Distributed id generator implementation
长沙学院2022暑假训练赛(一)六级阅读
随机推荐
为什么以太网无法接收大于1500字节的数据包?
【烂笔头】各厂商手机手动抓log
Explain the wait() function and waitpid() function in C language in detail
Distributed id generator implementation
VS2019常用快捷键
DDD 领域驱动设计
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道
MySQL高级特性之分布式(XA)事务的介绍
移远EC20 4G模块拨号相关
P7 Alibaba Interview Questions 2020.07 Sliding Window Algorithm (Alibaba Cloud Interview)
高项 04 项目整体管理
BeautifulSoup4的介绍与使用
VS2019 common shortcut keys
Integer 线程安全的
TCP segment of a reassembled PDU
AD的library中 库文件后缀有.intlib .schlib .pcblib 的区别
ByteDance Interview Questions: Mirror Binary Tree 2020
Use of PlantUML plugin in idea
RK3568商显版开源鸿蒙板卡产品解决方案
crc计算