报错:

MySQL第二天早上第一次连接超时报错,

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

原因:

上述问题是由mysql5数据库的配置引起的。mysql5将其连接的等待时间(wait_timeout 、interactive_timeout)缺省为8小时。在其客户程序中可以这样来查看其值:

  1. mysql> show global variables like 'wait_timeout';
  2.  
  3. mysql> SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';

如果在wait_timeout秒期间内,数据库连接(java.sql.Connection)一直处于等待状态,mysql5就将该连接关闭。这时,你的Java应用的连接池仍然合法地持有该连接的引用。当用该连接来进行数据库操作时,就碰到上述错误。这解释了为什么我的程序第二天不能登录 的问题。

解决办法:

在my.ini(windows) 或者/etc/my.cnf(linux) 中的 [mysqld]下添加:

  1. wait_timeout=31536000
  2. interactive_timeout=31536000

如:

重启mysql再次查看超时设置:

  1. [root@iZbp12b0psb88pmxixiwcsZ /]# /etc/init.d/mysqld restart
    ...
  2. mysql> SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';
  3. +---------------------+----------+
  4. | Variable_name | Value |
  5. +---------------------+----------+
  6. | interactive_timeout | 31536000 |
  7. +---------------------+----------+
  8. 1 row in set (0.00 sec)
  9.  
  10. mysql> show global variables like 'wait_timeout';
  11. +---------------+----------+
  12. | Variable_name | Value |
  13. +---------------+----------+
  14. | wait_timeout | 31536000 |
  15. +---------------+----------+
  16. 1 row in set (0.00 sec)

mysql 5.1超过默认8小时空闲时间解决办法(错误:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure)的更多相关文章

  1. 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 ...

  2. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决

    感谢大佬:https://blog.csdn.net/a704397849/article/details/93797529 springboot + mybatis多数据库 + druid连接池配置 ...

  3. 异常解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    异常描述 这个异常通常有如下信息: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failu ...

  4. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 数据库报错

    -- 查询mysql 数据库链接空闲时间持有最大空闲时间,单位为秒 SHOW VARIABLES WHERE VAriable_name = 'interactive_timeout'; -- 会出现 ...

  5. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决办法

    09:00:30.307 [http-8080-6] ERROR org.hibernate.transaction.JDBCTransaction -JDBC begin failed com.my ...

  6. Oozie时出现Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure?

    不多说,直接上干货! 问题详情 [hadoop@bigdatamaster oozie--cdh5.5.4]$ bin/ooziedb.sh create -sqlfile oozie.sql -ru ...

  7. Caused by: java.net.ConnectException: Connection refused/Caused by: java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    1.使用sqoop技术将mysql的数据导入到Hive出现的错误如下所示: 第一次使用命令如下所示: [hadoop@slaver1 sqoop--cdh5.3.6]$ bin/sqoop impor ...

  8. org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent succ

    数据库 没有开启  连接失败 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause ...

  9. mysql连接com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    现象:客户端连接服务器端mysql是没问题的,所有都木有问题,应用程序配置也没问题,但是连接就抛异常: com.mysql.jdbc.exceptions.jdbc4.CommunicationsEx ...

随机推荐

  1. python 使用pillow将图片转换为webp格式

    1.webp格式 webp格式是谷歌开发的一种旨在加快图片加载速度的格式,将图片转为webp格式后,体积约为原来的2/3,这可以节省大量的服务器带宽,微信公众号文章里的图片就是这种格式的. 2.使用p ...

  2. Eigen教程(9)

    整理下Eigen库的教程,参考:http://eigen.tuxfamily.org/dox/index.html Eigen并没有为matrix提供直接的Reshape和Slicing的API,但是 ...

  3. [转]uboot中SPI Flash Booting配置

    转自:https://e2echina.ti.com/question_answer/dsp_arm/sitara_arm/f/25/t/124834 最近和人一起调试SPI FLASH的配置问题,做 ...

  4. redis主从配置(docker实现)

    一.docker新建两个redis服务端,并分别设置端口为6379和6380 命令如下: docker run -p : -d --name redis-server docker.io/redis: ...

  5. andorid——自定义seekbar(转)

    xml 新建=>xml=>values <?xml version="1.0" encoding="utf-8"?> <resou ...

  6. 关于face alglimnment各种资料,存下来有空慢慢看

    人脸对齐和应用 机器学习--详解人脸对齐算法SDM-LBF 基于MTCNN的人脸自动对齐技术原理及其Tensorflow实现测试 人脸检测——MTCNN CVPR论文<Face Alignmen ...

  7. asp.net cookie的操作

    //写入 protected void Button2_Click(object sender, EventArgs e)     {         HttpCookie cookie=new Ht ...

  8. ansible普通用户su切换

    [root@361way.com ~]# cat /etc/ansible/hosts [test01] 10.212.52.14 ansible_ssh_user=test ansible_ssh_ ...

  9. nfs挂载hdfs,实现云存储

    本来不知道nfs是啥,因为群里的Harry童鞋有个问题,如何把本地目录挂载到hdfs上,搞什么云存储,说那么巧就是那么巧,HDP支持nfs,然后我就照着文档的说明去做,最后弄出来了. 1.修改机器上的 ...

  10. 【React全家桶入门之十】登录与身份认证

    细致想想,我们的后台系统还没有一个登录功能,太不靠谱,赶紧把防盗门安上! SPA的鉴权方式和传统的web应用不同:因为页面的渲染不再依赖服务端,与服务端的交互都通过接口来完毕,而REASTful风格的 ...