简体   繁体   English

错误代码:2013。查询30.002秒期间与MySQL服务器的连接断开

[英]Error Code: 2013. Lost connection to MySQL server during query 30.002 sec

There are a lot of issues with the same topic as mine but my content and issue seems to be different. 与我的主题有很多相同的问题,但是我的内容和问题似乎有所不同。 In my workbench, i run the code 在工作台中,我运行代码

`select(msgid) from `table`.log where 
 id = 'example'  and  status = 'active'  and month(created_at) = 12 
 and year(created_at) = 2018 limit 0,10;`

The above code works fine but when i run the code b 上面的代码工作正常,但是当我运行代码b

`select(msgid), count(msgid) from `table`.log where 
     id = 'example'  and  status = 'active'  and month(created_at) = 12 
     and year(created_at) = 2018 limit 0,10;`

i get the error 我得到错误

> Error Code: 2013. Lost connection to MySQL server during query 30.002 sec >错误代码:2013。查询30.002秒期间与MySQL服务器的连接断开

Why could this be happening in my workbench ? 为什么这会在我的工作台中发生?

PS: New to workbench and mysql PS:工作台和mysql的新手

Here's a screenshot of the preferences from MySQL Workbench 8.0.13. 这是MySQL Workbench 8.0.13中的首选项的屏幕截图。 I've put arrows indicating where you should select "SQL Editor" and then where you find the "DBMS connection read timeout interval" field. 我放置了箭头,指示应该在哪里选择“ SQL编辑器”,然后在哪里找到“ DBMS连接读取超时间隔”字段。

在此处输入图片说明

I agree with the comment from @SalmanA, you should optimize your query so it's not so slow. 我同意@SalmanA的评论,您应该优化查询,以免它变慢。

In particular, you should use indexes to help the query narrow down the rows to report. 特别是,您应该使用索引来帮助查询缩小要报告的行。 But you can't do that when you use functions like month(created_at) and year(created_at) . 但是,当您使用诸如month(created_at)year(created_at)类的函数时,您将无法做到这一点。 Presuming you have an index on created_at , you need to put that column by itself on the left side of comparison operators: 假设您在created_at上有一个索引,则需要将该列本身放在比较运算符的左侧:

... AND created_at >= '2018-12-01' AND created_at < '2019-01-01'

The best index for this query would be a compound index: 此查询的最佳索引是复合索引:

ALTER TABLE log ADD INDEX (id, status, created_at, msg_id);

You should try to increase DBMS connection read time out . 您应该尝试增加DBMS连接的读取超时。

Go to Workbench Edit → Preferences → SQL Editor → DBMS connections read time out : increase this to 6000 转到工作台编辑→首选项→SQL编辑器→DBMS连接读取超时:将其增加到6000

You can change timeout from : 您可以从更改超时:

Edit → Preferences → SQL Editor → DBMS connection read time out (in seconds): 600 编辑→首选项→SQL编辑器→DBMS连接读取超时(以秒为单位):600

Changed it to a greater value than your current. 将其更改为比当前值更大的值。

**UPDATE you can set read timeout also by: **更新您还可以通过以下方式设置读取超时:

SET @@local.net_read_timeout=360;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PDO查询错误:2013查询期间失去与MySQL服务器的连接[需要优化帮助] - PDO Query Error: 2013 Lost connection to MySQL server during query [Need Optimization Help] 记录在 40 秒后显示,有时在查询期间出现“与 MySQL 服务器的连接丢失” - Records are dislaying after 40 sec and sometimes getting "Lost connection to MySQL server" during query 查询异常期间失去与MySQL服务器的连接 - Lost connection to MySQL server during query exception 查询期间失去与MySQL Server的连接 - Connection lost to MySQL Server during query 查询时与MySQL服务器失去连接 In codeigniter query,Live site - Lost connection to MySQL server during query In codeigniter query ,Live site 查询期间失去与MySQL服务器的连接-PHP,MySQL - Lost connection to MySQL server during query - PHP, MySQL 异常后如何在php adodb中重新连接:MySQL服务器消失或查询期间与MySQL服务器的连接断开 - How to reconnect in php adodb after exceptions: Mysql server gone away or Lost connection to MySQL server during query PHP,MySQL,查询过程中与MySQL服务器的连接断开,TurnKey Ubuntu / Linux, - PHP, MySQL, Lost connection to MySQL server during query, TurnKey Ubuntu/Linux, 与 MySQL 服务器的连接丢失(错误:111) - Connection to MySQL server lost (error:111) 失去与MySQL服务器的连接,系统错误:111 - Lost connection to MySQL server, system error: 111
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM