错误代码:2013。在查询过程中失去与 MySQL 服务器的连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10563619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:21:04  来源:igfitidea点击:

Error Code: 2013. Lost connection to MySQL server during query

mysqlsqldatabasemysql-workbench

提问by user836026

I got the Error Code: 2013. Lost connection to MySQL server during queryerror when I tried to add an index to a table using MySQL Workbench. I noticed also that it appears whenever I run long query.

我收到错误代码:2013。当我尝试使用 MySQL Workbench 将索引添加到表时,在查询错误期间丢失了与 MySQL 服务器的连接。我还注意到,每当我运行长查询时它就会出现。

Is there away to increase the timeout value?

是否可以增加超时值?

回答by eric william nord

New versions of MySQL WorkBench have an option to change specific timeouts.

新版本的 MySQL WorkBench 可以选择更改特定超时。

For me it was under Edit → Preferences → SQL Editor → DBMS connection read time out (in seconds): 600

对我来说,它是在 Edit → Preferences → SQL Editor → DBMS connection read time out (in seconds): 600

Changed the value to 6000.

将值更改为 6000。

Also unchecked limit rows as putting a limit in every time I want to search the whole data set gets tiresome.

还有未经检查的限制行,因为每次我想搜索整个数据集时都设置一个限制会让人厌烦。

回答by Yahia

Start the DB server with the comandline option net_read_timeout/ wait_timeoutand a suitable value (in seconds) - for example: --net_read_timeout=100.

使用命令行选项net_read_timeout/wait_timeout和合适的值(以秒为单位)启动数据库服务器- 例如:--net_read_timeout=100

For reference see hereand here.

有关参考,请参阅此处此处

回答by Harti

If your query has blob data, this issue can be fixed by applying a my.inichange as proposed in this answer:

如果您的查询包含 blob 数据,则可以通过应用此答案中建议my.ini更改来解决此问题

[mysqld]
max_allowed_packet=16M

By default, this will be 1M (the allowed maximum value is 1024M). If the supplied value is not a multiple of 1024K, it will automatically be rounded to the nearest multiple of 1024K.

默认情况下,这将为 1M(允许的最大值为 1024M)。如果提供的值不是 1024K 的倍数,它将自动四舍五入到最接近的 1024K 倍数。

While the referenced thread is about the MySQL error 2006, setting the max_allowed_packetfrom 1M to 16M didfix the 2013 error that showed up for me when running a long query.

虽然引用的线程是关于 MySQL 错误2006,但将max_allowed_packet1M设置为 16M确实修复了运行长查询时出现的 2013 错误。

For WAMP users: you'll find the flag in the [wampmysqld]section.

对于 WAMP 用户:您将在[wampmysqld]部分中找到该标志。

回答by MysqlMan

Add the following into /etc/mysql/cnf file:

将以下内容添加到 /etc/mysql/cnf 文件中:

innodb_buffer_pool_size = 64M

example:

例子:

key_buffer              = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
innodb_buffer_pool_size = 64M

回答by user1313024

SET @@local.net_read_timeout=360;

Warning: The following will not work when you are applying it in remote connection:

警告:当您在远程连接中应用它时,以下内容将不起作用:

SET @@global.net_read_timeout=360;

回答by Nanhe Kumar

There are three likely causes for this error message

此错误消息有三个可能的原因

  1. Usually it indicates network connectivity trouble and you should check the condition of your network if this error occurs frequently
  2. Sometimes the “during query” form happens when millions of rows are being sent as part of one or more queries.
  3. More rarely, it can happen when the client is attempting the initial connection to the server
  1. 通常表示网络连接有问题,如果经常出现此错误,您应该检查网络状况
  2. 有时,当作为一个或多个查询的一部分发送数百万行时,会出现“查询期间”表单。
  3. 更罕见的是,当客户端尝试初始连接到服务器时可能会发生这种情况

For more detail read >>

更多详情 请阅读>>

Cause 2 :

原因2:

SET GLOBAL interactive_timeout=60;

from its default of 30 seconds to 60 seconds or longer

从默认的 30 秒到 60 秒或更长

Cause 3 :

原因3:

SET GLOBAL connect_timeout=60;

回答by user2286136

Thanks!It's worked. But with the mysqldb updates the configure has became:

谢谢!成功了。但是随着 mysqldb 更新,配置变成了:

max_allowed_packet

net_write_timeout

net_read_timeout

max_allowed_pa​​cket

net_write_timeout

net_read_timeout

mysql doc

mysql 文档

回答by Maksym Polshcha

You should set the 'interactive_timeout' and 'wait_timeout' properties in the mysql config file to the values you need.

您应该将 mysql 配置文件中的“interactive_timeout”和“wait_timeout”属性设置为您需要的值。

回答by Shoaib Khan

Just perform a MySQL upgrade that will re-build innoDB engine along with rebuilding of many tables required for proper functioning of MySQL such as performance_schema, information_schema, etc.

只需执行一个MySQL升级,将重新构建InnoDB引擎进行MySQL等的正常运作所需的许多表的重建一起performance_schemainformation_schema等等。

Issue the below command from your shell:

从您的 shell 发出以下命令:

sudo mysql_upgrade -u root -p

回答by Aamir Mahmood

I know its old but on mac

我知道它很旧,但在 mac 上

1. Control-click your connection and choose Connection Properties.
2. Under Advanced tab, set the Socket Timeout (sec) to a larger value.