MySQL每隔一小会不操作报错ERROR 2013 (HY000) Lost connection to MySQL server during query问题

Posted PiscesCanon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL每隔一小会不操作报错ERROR 2013 (HY000) Lost connection to MySQL server during query问题相关的知识,希望对你有一定的参考价值。

 

MySQL每隔一小会不操作报错ERROR 2013 (HY000) Lost connection to MySQL server during query问题

 

连接OA的MySQL库发现每隔一小会不操作就报错如下:

mysql> select now();
+
| now()               |
+
| 2022-01-11 09:47:41 |
+
1 row in set (0.00 sec)

mysql> select now();
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> select now();
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    453751
Current database: *** NONE ***

+
| now()               |
+
| 2022-01-11 09:48:27 |
+
1 row in set (0.00 sec)

 

 

实际上有两个参数如下:

interactive_timeout = 1800  ##交互式会话空闲超时时间(mysql工具、mysqldump等)

wait_timeout = 1800  ##非交互式会话空闲超时时间,mysql api程序,jdbc连接数据库等

 

查看数据库的这两个参数值(单位:s):

mysql> show variables where Variable_name in (\'interactive_timeout\',\'wait_timeout\');
+
| Variable_name       | Value |
+
| interactive_timeout | 30    |
| wait_timeout        | 30    |
+
2 rows in set (0.00 sec)

 

由于我是使用mysql数据库本身的命令行交互式客户端mysql,因此调整调整interactive_timeout的值即可。

通过调整interactive_timeout=10,30,60后,会话1连接进去不操作,会话2持续观察:

会话2:
mysql> show full processlist; + | Id | User | Host | db | Command | Time | State | Info | + | 2 | root | ::1:53493 | td_oa | Sleep | 1 | | NULL | | 41 | root | ::1:53566 | td_oa | Sleep | 28 | | NULL | | 45 | root | ::1:53574 | td_oa | Sleep | 20 | | NULL | | 1709 | root | ::1:56311 | td_oa | Sleep | 68 | | NULL | | 454546 | root | 192.168.1.188:54046 | NULL | Sleep | 7 | | NULL | | 454553 | root | 192.168.1.188:54048 | NULL | Query | 0 | init | show full processlist | + 6 rows in set (0.00 sec)

 

以上是关于MySQL每隔一小会不操作报错ERROR 2013 (HY000) Lost connection to MySQL server during query问题的主要内容,如果未能解决你的问题,请参考以下文章

MySQL报错:ERROR 2013 (HY000): Lost connection to MySQL server during query

mysqldump导出报错"mysqldump: Error 2013: Lost connection to MySQL server during query when dumping

navicat连接MySQL出现 Error_code:2013的错误

MySQL ERROR 1064 (42000)——不管怎样grant总是报错,怎么回事?

(Win/C#/.Net) Applet 需要每隔一小时轮询一次——关于最佳方法的建议?

mysql 报错 get error 28 from storage engine 解决方法