Communications link failure的解决办法

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: Communications link failure的解决办法

使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误:

Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was ***  millisecond ago。

其中错误还会提示你修改wait_timeout或是使用Connector/J的autoReconnect属性避免该错误。

后来查了一些资料,才发现遇到这个问题的人还真不少,

大部分都是使用连接池方式时才会出现这个问题,短连接应该很难出现这个问题。

这个问题的其中一个原因:

MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,

MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),

当应用申请使用该连接时,就会导致上面的报错。

修改MySQL的参数,wait_timeout最大为31536000即1年,在my.cnf中加入:

my.cnf位置在MySQL安装目录下:

[mysqld]

wait_timeout=31536000

interactive_timeout=31536000

重启mysql服务生效,需要同时修改这两个参数。

其他原因类似断网,修改端口号,mysql服务未开启等

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
SQL 关系型数据库 分布式数据库
Communications link failure
Communications link failure
176 1
|
关系型数据库 MySQL 数据库
|
4月前
|
iOS开发 MacOS
mac AnyConnect 连接报错 Posture Assessment Failed: Hostscan Initialize error.
mac AnyConnect 连接报错 Posture Assessment Failed: Hostscan Initialize error.
mac AnyConnect 连接报错 Posture Assessment Failed: Hostscan Initialize error.
|
5月前
|
存储 Cloud Native Linux
Failed to open/create the internal network ‘HostInterfaceNetworking-VirtualBox Host-Only Ethernet
Failed to open/create the internal network ‘HostInterfaceNetworking-VirtualBox Host-Only Ethernet
|
开发工具 Android开发
解决bug:使用Genymotion模拟器时,出现Unable to create virtual device: Connection timeout occurred
解决bug:使用Genymotion模拟器时,出现Unable to create virtual device: Connection timeout occurred
114 0
解决bug:使用Genymotion模拟器时,出现Unable to create virtual device: Connection timeout occurred
|
iOS开发
Xcode报错:Failed to find a suitable device for the type SimDeviceType解决方法
Xcode报错:Failed to find a suitable device for the type SimDeviceType解决方法
182 0
|
关系型数据库 MySQL Java
|
区块链
Error: No network specified. Cannot determine current network异常
Error: No network specified. Cannot determine current network异常
131 0
|
数据库
Symantec Backup Exec Agent 推送错误Error connecting to the remote computer. Ensure that the computer is available, has WMI enabled and is not blocked by a
如果在Symantec Backup Server上推送Symantec Backup Exec Agent到数据库服务器遇到“"Error connecting to the remote computer. Ensure that the computer is available, has WMI enabled and is not blocked by a firewall"这个错误, 如下截图所示     那么完全可以参考下面官方提供的三个解决方案解决问题,几次碰到这个问题,每次都要搜索一下,特此记录一下,方便以后查找。
1305 0
|
iOS开发
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun ...
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun image.png 解决方法: 打开终端输入 xcode-select --install 回车后,系统弹出下载xcode,点击确认,下载完成后即可。
1646 0