简体   繁体   English

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

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

I got the Error Code: 2013. Lost connection to MySQL server during query error when I tried to add an index to a table using MySQL Workbench.我收到错误代码:2013。当我尝试使用 MySQL Workbench 向表添加索引时,在查询错误期间丢失了与 MySQL 服务器的连接 I noticed also that it appears whenever I run long query.我还注意到,每当我运行长查询时它就会出现。

Is there away to increase the timeout value?是否可以增加超时值?

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.还有未经检查的限制行,因为每次我想搜索整个数据集时都设置一个限制会让人厌烦。

If your query has blob data, this issue can be fixed by applying a my.ini change 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).默认情况下,这将为 1M(允许的最大值为 1024M)。 If the supplied value is not a multiple of 1024K, it will automatically be rounded to the nearest multiple of 1024K.如果提供的值不是 1024K 的倍数,它将自动四舍五入为最接近的 1024K 倍数。

While the referenced thread is about the MySQL error 2006 , setting the max_allowed_packet from 1M to 16M did fix the 2013 error that showed up for me when running a long query.虽然引用的线程是关于 MySQL 错误2006 ,但将max_allowed_packet从 1M 设置为 16M确实修复了运行长查询时出现的 2013 错误。

For WAMP users: you'll find the flag in the [wampmysqld] section.对于 WAMP 用户:您将在[wampmysqld]部分找到该标志。

Start the DB server with the comandline option net_read_timeout / wait_timeout and a suitable value (in seconds) - for example: --net_read_timeout=100 .使用命令行选项net_read_timeout / wait_timeout和合适的值(以秒为单位)启动数据库服务器 - 例如: --net_read_timeout=100

For reference see here and here .有关参考,请参阅此处此处

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
SET @@local.net_read_timeout=360;

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

SET @@global.net_read_timeout=360;

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

I got the Error Code: 2013. Lost connection to MySQL server during query error when I tried to add an index to a table using MySQL Workbench.我收到错误代码:2013。当我尝试使用MySQL Workbench向表中添加索引时,在查询错误期间失去了与MySQL服务器的连接 I noticed also that it appears whenever I run long query.我还注意到,只要我运行长时间查询,它就会出现。

Is there away to increase the timeout value?是否有增加超时值的方法?

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更罕见的是,当客户端尝试与服务器进行初始连接时会发生这种情况

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;

In my case, setting the connection timeout interval to 6000 or something higher didn't work.就我而言,将连接超时间隔设置为 6000 或更高的值不起作用。

I just did what the workbench says I can do.我只是做了工作台说我可以做的事情。

The maximum amount of time the query can take to return data from the DBMS.Set 0 to skip the read timeout.查询从 DBMS 返回数据所需的最长时间。设置 0 以跳过读取超时。

On Mac Preferences -> SQL Editor -> Go to MySQL Session -> set connection read timeout interval to 0.在 Mac Preferences -> SQL Editor -> Go to MySQL Session -> 将连接读取超时间隔设置为 0。

And it works 😄它有效😄

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

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.

If you experience this problem during the restore of a big dump-file and can rule out the problem that it has anything to do with network (eg execution on localhost) than my solution could be helpful.如果您在恢复大转储文件期间遇到此问题并且可以排除它与网络有关的问题(例如在本地主机上执行),那么我的解决方案可能会有所帮助。

My mysqldump held at least one INSERT that was too big for mysql to compute.我的 mysqldump 至少保存了一个对 mysql 来说太大而无法计算的 INSERT。 You can view this variable by typing show variables like "net_buffer_length";您可以通过键入show variables like "net_buffer_length";来查看此变量show variables like "net_buffer_length"; inside your mysql-cli.在你的 mysql-cli 里面。 You have three possibilities:你有三种可能:

  • increase net_buffer_length inside mysql -> this would need a server restart增加 mysql 内的 net_buffer_length -> 这需要重启服务器
  • create dump with --skip-extended-insert , per insert one line is used -> although these dumps are much nicer to read this is not suitable for big dumps > 1GB because it tends to be very slow使用--skip-extended-insert创建转储,每个插入使用一行 -> 虽然这些转储更好读,但这不适合 > 1GB 的大转储,因为它往往很慢
  • create dump with extended inserts (which is the default) but limit the net-buffer_length eg with --net-buffer_length NR_OF_BYTES where NR_OF_BYTES is smaller than the server's net_buffer_length -> I think this is the best solution, although slower no server restart is needed.创建带有扩展插入的转储(这是默认值)但限制 net-buffer_length 例如使用--net-buffer_length NR_OF_BYTES其中 NR_OF_BYTES 小于服务器的 net_buffer_length -> 我认为这是最好的解决方案,虽然速度较慢,但​​不需要重新启动服务器.

I used following mysqldump command: mysqldump --skip-comments --set-charset --default-character-set=utf8 --single-transaction --net-buffer_length 4096 DBX > dumpfile我使用了以下 mysqldump 命令: mysqldump --skip-comments --set-charset --default-character-set=utf8 --single-transaction --net-buffer_length 4096 DBX > dumpfile

Try please to uncheck limit rows in in Edit → Preferences →SQL Queries请尝试在编辑→首选项→SQL查询中取消选中限制行

because 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' 属性设置为您需要的值。

在 Edit->Preferences->SQL editor->MySQL session 中更改“读取超时”时间

Sometimes your SQL-Server gets into deadlocks, I've been in to this problem like 100 times.有时您的 SQL-Server 会陷入死锁,我已经遇到这个问题 100 次了。 You can either restart your computer/laptop to restart server (easy way) OR you can go to task-manager>services>YOUR-SERVER-NAME(for me , it was MySQL785 something like this).您可以重新启动计算机/笔记本电脑以重新启动服务器(简单的方法),或者您可以转到任务管理器>服务>您的服务器名称(对我来说,它是 MySQL785 之类的东西)。 And right-click > restart.然后右键单击>重新启动。 Try executing query again.再次尝试执行查询。

I got the same issue when loading a .csv file.加载 .csv 文件时我遇到了同样的问题。 Converted the file to .sql.将文件转换为 .sql。

Using below command I manage to work around this issue.使用下面的命令,我设法解决了这个问题。

mysql -u <user> -p -D <DB name> < file.sql

Hope this would help.希望这会有所帮助。

If all the other solutions here fail - check your syslog (/var/log/syslog or similar) to see if your server is running out of memory during the query.如果这里的所有其他解决方案都失败了 - 检查您的系统日志(/var/log/syslog 或类似的)以查看您的服务器在查询期间是否内存不足。

Had this issue when innodb_buffer_pool_size was set too close to physical memory without a swapfile configured.在没有配置交换文件的情况下将 innodb_buffer_pool_size 设置得太接近物理内存时会出现此问题。 MySQL recommends for a database specific server setting innodb_buffer_pool_size at a max of around 80% of physical memory , I had it set to around 90%, the kernel was killing the mysql process. MySQL 建议将特定于数据库的服务器设置 innodb_buffer_pool_size 最大为物理内存的 80% 左右,我将其设置为 90% 左右,内核正在杀死 mysql 进程。 Moved innodb_buffer_pool_size back down to around 80% and that fixed the issue.将 innodb_buffer_pool_size 移回 80% 左右,从而解决了问题。

I faced this same issue.我遇到了同样的问题。 I believe it happens when you have foreign keys to larger tables (which takes time).我相信当您有更大表的外键时会发生这种情况(这需要时间)。

I tried to run the create table statement again without the foreign key declarations and found it worked.我尝试在没有外键声明的情况下再次运行 create table 语句,发现它有效。

Then after creating the table, I added the foreign key constrains using ALTER TABLE query.然后在创建表后,我使用 ALTER TABLE 查询添加了外键约束。

Hope this will help someone.希望这会帮助某人。

This happened to me because my innodb_buffer_pool_size was set to be larger than the RAM size available on the server.这发生在我身上,因为我的 innodb_buffer_pool_size 设置为大于服务器上可用的 RAM 大小。 Things were getting interrupted because of this and it issues this error.事情因此而中断,并发出此错误。 The fix is to update my.cnf with the correct setting for innodb_buffer_pool_size.修复方法是使用 innodb_buffer_pool_size 的正确设置更新 my.cnf。

转到工作台编辑 → 首选项 → SQL 编辑器 → DBMS 连接读取超时:最多 3000。错误不再发生。

Go to:去:

Edit -> Preferences -> SQL Editor编辑 -> 首选项 -> SQL 编辑器

In there you can see three fields in the "MySQL Session" group, where you can now set the new connection intervals (in seconds).在那里您可以看到“MySQL Session”组中的三个字段,您现在可以在其中设置新的连接间隔(以秒为单位)。

Turns out our firewall rule was blocking my connection to MYSQL.原来我们的防火墙规则阻止了我与 MYSQL 的连接。 After the firewall policy is lifted to allow the connection i was able to import the schema successfully.在解除防火墙策略以允许连接后,我能够成功导入架构。

I had the same problem - but for me the solution was a DB user with too strict permissions.我遇到了同样的问题 - 但对我来说,解决方案是权限太严格的数据库用户。 I had to allow the Execute ability on the mysql table.我必须允许mysql表上的Execute能力。 After allowing that I had no dropping connections anymore允许后,我不再断开连接

Check if the indexes are in place first.首先检查索引是否到位。

SELECT *
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = '<schema>'

I ran into this while running a stored proc- which was creating lots of rows into a table in the database.我在运行一个存储过程时遇到了这个问题——它在数据库的一个表中创建了很多行。 I could see the error come right after the time crossed the 30 sec boundary.我可以看到错误在时间越过 30 秒边界后立即出现。

I tried all the suggestions in the other answers.我尝试了其他答案中的所有建议。 I am sure some of it helped , however- what really made it work for me was switching to SequelPro from Workbench.我相信其中一些帮助,但是 - 真正让我工作的是从 Workbench 切换到 SequelPro。

I am guessing it was some client side connection that I could not spot in Workbench.我猜这是我在 Workbench 中找不到的一些客户端连接。 Maybe this will help someone else as well ?也许这也会对其他人有所帮助?

If you are using SQL Work Bench, you can try using Indexing, by adding an index to your tables, to add an index, click on the wrench(spanner) symbol on the table, it should open up the setup for the table, below, click on the index view, type an index name and set the type to index, In the index columns, select the primary column in your table.如果您使用的是 SQL Work Bench,您可以尝试使用索引,通过向表添加索引,添加索引,单击表上的扳手(扳手)符号,它应该会打开表的设置,如下所示,单击索引视图,键入索引名称并将类型设置为索引,在索引列中,选择表中的主列。

Do the same step for other primary keys on other tables.对其他表上的其他主键执行相同的步骤。

There seems to be an answer missing here for those using SSH to connect to their MySQL database.对于那些使用 SSH 连接到他们的 MySQL 数据库的人来说,这里似乎缺少一个答案。 You need to check two places not 1 as suggested by other answers:您需要按照其他答案的建议检查两个不是 1 的地方:

Workbench Edit → Preferences → SQL Editor → DBMS工作台编辑 → 首选项 → SQL 编辑器 → DBMS

Workbench Edit → Preferences → SSH → Timeouts工作台编辑 → 首选项 → SSH → 超时

My default SSH Timeouts were set very low and causing some (but apparently not all) of my timeout issues.我的默认 SSH 超时设置得非常低,导致我的一些(但显然不是全部)超时问题。 After, don't forget to restart MySQL Workbench!之后,不要忘记重新启动 MySQL Workbench!

Last, it may be worth contacting your DB Admin and asking them to increase wait_timeout & interactive_timeout properties in mysql itself via my.conf + mysql restart or doing a global set if restarting mysql is not an option.最后,可能值得联系您的数据库管理员并要求他们通过 my.conf + mysql restart 增加 mysql 本身中的 wait_timeout 和 interactive_timeout 属性,或者如果无法重新启动 mysql,则进行全局设置。

Hope this helps!希望这可以帮助!

Three things to be followed and make sure:要遵循并确保以下三件事:

  1. Whether multiple queries show lost connection?多个查询是否显示连接丢失?
  2. how you use set query in MySQL?你如何在 MySQL 中使用 set 查询?
  3. how delete + update query simultaneously?如何同时删除+更新查询?

Answers:答案:

  1. Always try to remove definer as MySQL creates its own definer and if multiple tables involved for updation try to make a single query as sometimes multiple query shows lost connection总是尝试删除定义器,因为 MySQL 创建了自己的定义器,如果更新涉及多个表,请尝试进行单个查询,因为有时多个查询显示连接丢失
  2. Always SET value at the top but after DELETE if its condition doesn't involve SET value.如果条件不涉及 SET 值,则始终在顶部设置值,但在 DELETE 之后。
  3. Use DELETE FIRST THEN UPDATE IF BOTH OF THEM OPERATIONS ARE PERFORMED ON DIFFERENT TABLES如果两个操作都在不同的表上执行,请先使用删除然后更新

I had this error message due to a problem after of upgrade Mysql.由于升级 Mysql 后出现问题,我收到此错误消息。 The error appeared immediately after I tried to do any query在我尝试执行任何查询后立即出现错误

Check mysql error log files in path /var/log/mysql (linux)检查路径/var/log/mysql (linux) 中的 mysql 错误日志文件

In my case reassigning Mysql owner to the Mysql system folder worked for me在我的情况下,将 Mysql 所有者重新分配给 Mysql 系统文件夹对我有用

chown -R mysql:mysql /var/lib/mysql

Establish connection first mysql --host=host.com --port=3306 -u username -p then select your db use dbname then source dumb source C:\\dumpfile.sql .首先建立连接mysql --host=host.com --port=3306 -u username -p然后选择你的数据库use dbname然后 source 哑source C:\\dumpfile.sql After it's done \\q完成后\\q

My observation -我的观察——

when you run MySQL Workbench and terminal together and in terminal you do -当您一起运行 MySQL Workbench 和终端并在终端中运行时 -

SET AUTOCOMMIT = 0;

OR或者

START TRANSACTION;

Then you usually face this kind of problem.那么你通常会面临这样的问题。

And even after -甚至之后——

SET AUTOCOMMIT = 1;

OR或者

COMMIT;

The problems persists.问题依然存在。

You need to logout from both terminal and MYSQL workbench and then login again or else do a reboot.您需要从终端和 MYSQL 工作台注销,然后再次登录或重新启动。

check about检查一下

OOM on /var/log/messages ,
modify innodb_buffer_pool_size value ; when load data , use 50% of os mem ; 

Hope this helps希望这可以帮助

This usually means that you have "incompatibilities with the current version of MySQL Server", see mysql_upgrade.这通常意味着您“与当前版本的 MySQL 服务器不兼容”,请参阅 mysql_upgrade。 I ran into this same issue and simply had to run:我遇到了同样的问题,只需要运行:

mysql_upgrade --password The documentation states that, "mysql_upgrade should be executed each time you upgrade MySQL". mysql_upgrade --password 文档指出,“每次升级 MySQL 时都应执行 mysql_upgrade”。

暂无
暂无

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

相关问题 错误代码:2013。运行 MySQL 查询时,在查询期间失去与 MySQL 服务器的连接 - Error Code: 2013. Lost connection to MySQL server during query when running MySQL query MySQL中的错误调用过程:错误代码:2013。查询期间与MySQL服务器的连接断开 - Error calling procedure in MySQL: Error Code: 2013. Lost connection to MySQL server during query Mysql:错误代码:2013。查询期间与MySQL服务器的连接断开 - Mysql: Error Code: 2013. Lost connection to MySQL server during query 无法在 MySQL 数据库中创建表(错误代码:2013。在查询过程中与 MySQL 服务器的连接丢失) - Unable to Create a Table in MySQL Database (Error Code: 2013. Lost connection to MySQL server during query) mysql,错误代码:2013。查询期间与MySQL服务器的连接断开 - mysql, Error Code: 2013. Lost connection to MySQL server during query MySQL(游标/存储过程):错误代码:2013。在查询 6000.015 秒期间丢失与 MySQL 服务器的连接 - MySQL(Cursors/stored procedures): Error Code: 2013. Lost connection to MySQL server during query 6000.015 sec 错误代码:2013。查询30.002秒期间与MySQL服务器的连接断开 - Error Code: 2013. Lost connection to MySQL server during query 30.002 sec 错误代码:2013。尽管时间未超过限制,但在查询过程中失去了与MySQL服务器的连接 - Error Code: 2013. Lost connection to MySQL server during query though the time hasn't exceeded the limit docker 中的 MariaDB 说 - 错误代码:2013。在查询期间失去与 MySQL 服务器的连接 - MariaDB in docker said - Error Code: 2013. Lost connection to MySQL server during query MySQL-错误2013:查询期间与MySQL服务器的连接断开-Localhost - MySQL - Error 2013: Lost Connection to MySQL server during Query - Localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM