MySQL Connection timeout problem solution

Source: Internet
Author: User

Program backstage this error at com.mysql.jdbc.MysqlIO.readFully (mysqlio.java:2332), * * End NESTED EXCEPTION * * Last packet sent to the "s Erver was Ms ago.

The main reason for this problem is that the application server has not been connected to MySQL for a long time, exceeding the maximum timeout set by MySQL, and then connecting to MySQL will appear this problem.

MySQL default setting is 8 hours, the general web site during the day have been visited, from night to morning generally will be more than 8 hours, so the visit will be the problem.

The simple solution is to modify the maximum timeout, for example, to 12 hours or 10 hours, which avoids the time of no access and is modified to 10 hours, as follows:

It seems that the next wait_timeout is only 15 really not the general short, the system defaults installed is trouble.


Open MySQL console, run: Show variables like '%timeout% ', view and connect time related to MySQL system variables

can be set under

The code is as follows Copy Code

Mysql> Show variables like '%timeout ';

+ —————————-+ ——-+
| variable_name | Value |
+ —————————-+ ——-+
| Connect_timeout | 15 |
| 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 | 15 |
+ —————————-+ ——-+
Rows in Set (0.00 sec)

Set Wait_timeout length directly

The code is as follows Copy Code

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 | 15 |
| 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 |
+ —————————-+ ——-+
Rows in Set (0.00 sec)


I think the simplest way is to prescribe the right remedy: Since the problem is caused by the default value of the MYSQL5 global variable wait_timeout is too small, we will change it to large.

Check the MYSQL5 manual and find that the maximum value for Wait_timeout is 24 days/365 days (Windows/linux) respectively. Take Windows for example, assuming that we want to set it to 21 days, we simply modify the MYSQL5 profile "My.ini" (mysql5 installation dir) to add one line:

[Mysqld]

The code is as follows Copy Code

wait_timeout=31536000
interactive_timeout=31536000

A reboot of the MYSQL5 is required.

Linux system configuration file:/etc/my.cnf

The test display problem is resolved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.