有很多与我的主题相同的问题,但我的内容和问题似乎不同。在我的工作台中,我运行代码
`select(msgid) from `table`.log where
id = 'example' and status = 'active' and month(created_at) = 12
and year(created_at) = 2018 limit 0,10;`
上面的代码工作正常,但是当我运行代码时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;`
我收到错误
> Error Code: 2013. Lost connection to MySQL server during query 30.002 sec
为什么我的工作台会发生这种情况?
PS:workbench 和 mysql 新手
最佳答案
这是 MySQL Workbench 8.0.13 的首选项屏幕截图。我放置了箭头,指示应在何处选择“SQL 编辑器”,然后在何处找到“DBMS 连接读取超时间隔”字段。
我同意@SalmanA 的评论,你应该优化你的查询,这样它就不会那么慢。
特别是,您应该使用索引来帮助查询缩小要报告的行的范围。但当您使用 month(created_at)
和 year(created_at)
等函数时,您就无法执行此操作。假设您在 created_at
上有一个索引,您需要将该列单独放在比较运算符的左侧:
... AND created_at >= '2018-12-01' AND created_at < '2019-01-01'
此查询的最佳索引是复合索引:
ALTER TABLE log ADD INDEX (id, status, created_at, msg_id);
关于php - 错误代码 : 2013. 在查询 30.002 秒期间失去与 MySQL 服务器的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54011056/