zoukankan      html  css  js  c++  java
  • MYSQL超时连接问题(com.mysql.jdbc.MysqlIO.readFully)

    应用服务器连接mysql,有时候会出现以下异常:

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_95]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_95]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_95]
    Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3161) ~[mysql-connector-java-5.1.31.jar:na]
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3615) ~[mysql-connector-java-5.1.31.jar:na]
    ... 43 common frames omitted

    这个问题主要原因是应用服务器很长时间没有连接mysql,超过了mysql设置的最大超时时间,再连接mysql就会出现这个问题。mysql默认设置是8小时,一般网站白天都有人访问,从夜里到早上一般都会超过8小时,所以再来访问就会这个问题。

    简单的解决办法就是修改最大超时时间,比如改为12小时或10小时,这样恰好避免了无人访问的时段,这里修改为10小时,方法如下:

    mysql> show variables like '%timeout';
    +----------------------------+-------+
    | Variable_name              | Value |
    +----------------------------+-------+
    | connect_timeout            | 10    |
    | delayed_insert_timeout     | 300   |
    | innodb_lock_wait_timeout   | 50    |
    | innodb_rollback_on_timeout | OFF   |
    | interactive_timeout        | 28800 |
    | net_read_timeout           | 30    |
    | net_write_timeout          | 60    |
    | slave_net_timeout          | 3600  |
    | table_lock_wait_timeout    | 50    |
    | wait_timeout               | 28800 |
    +----------------------------+-------+
    10 rows in set (0.00 sec)

    mysql> set wait_timeout = 36000;
    Query OK, 0 rows affected (0.00 sec)

    mysql> set interactive_timeout = 36000;
    Query OK, 0 rows affected (0.00 sec)

    mysql> show variables like '%timeout';
    +----------------------------+-------+
    | Variable_name              | Value |
    +----------------------------+-------+
    | connect_timeout            | 10    |
    | delayed_insert_timeout     | 300   |
    | innodb_lock_wait_timeout   | 50    |
    | innodb_rollback_on_timeout | OFF   |
    | interactive_timeout        | 36000 |
    | net_read_timeout           | 30    |
    | net_write_timeout          | 60    |
    | slave_net_timeout          | 3600  |
    | table_lock_wait_timeout    | 50    |
    | wait_timeout               | 36000 |
    +----------------------------+-------+
    10 rows in set (0.00 sec)

  • 相关阅读:
    File
    Include and Require
    Date and Time
    css3的nth-child选择器使用示例
    document.title
    php获取从百度搜索进入网站的关键词的详细代码
    Iphone手机、安卓手机浏览器控制默认缩放大小的方法
    离线宝调用
    织梦DedeCMS网站地图模板
    禁止选择文本和禁用右键 v3.0
  • 原文地址:https://www.cnblogs.com/libaoting/p/mysql.html
Copyright © 2011-2022 走看看