MySQL 错误 2006 (HY000) 在第 406 行:MySQL 服务器已经消失
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8744813/
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
MySQL Error 2006 (HY000) at line 406: MySQL server has gone away
提问by David
I have a MYSQL dump from a database that I am trying to move to a new db server. When I try to import my sql dump, I receive the following error:
我有一个来自数据库的 MYSQL 转储,我正试图将其移至新的 db 服务器。当我尝试导入我的 sql 转储时,我收到以下错误:
MySQL Error 2006 (HY000) at line 406: MySQL server has gone away
I googled the problem and most people fixed the problem by changing the value of wait_timeout. However, my current value is set to 28800 (8 hours) and the error appears in less than 8 seconds when I run the import.
我在 google 上搜索了这个问题,大多数人通过更改 wait_timeout 的值解决了这个问题。但是,我的当前值设置为 28800(8 小时),并且在我运行导入时错误会在 8 秒内出现。
I also tried setting the value of max_allowed_packet to 1073741824 but that also did not fix the problem.
我也尝试将 max_allowed_packet 的值设置为 1073741824 但这也没有解决问题。
Looking through the mysql dump, there are quite a few blob columns in the dump, but the overall file size is only 6 MB.
查看mysql转储,转储中有相当多的blob列,但整体文件大小只有6 MB。
Does anyone have any ideas about what else might be the problem?
有没有人对其他可能的问题有任何想法?
回答by Pauli Price
Adding this answer for the benefit of future searchers, as it explains why increasing the packet size fixed the problem:
添加这个答案是为了未来搜索者的利益,因为它解释了为什么增加数据包大小可以解决这个问题:
The situation is that if a client sends a SQL-statement longer than the server max_allowed_packet setting, the server will simply disconnect the client. Next query from the same client instance will find that the ‘MySQL server has gone away'.
... But it would of course be much preferable to have the ‘got packet bigger' error [Error: 2020 (CR_NET_PACKET_TOO_LARGE)] returned if that is the problem.
情况是,如果客户端发送的 SQL 语句长于服务器 max_allowed_packet 设置,服务器将简单地断开客户端连接。来自同一客户端实例的下一个查询将发现“MySQL 服务器已消失”。
...但当然,如果这是问题,返回“数据包更大”错误 [Error: 2020 (CR_NET_PACKET_TOO_LARGE)] 会更好。
Excerpted from and thanks for peter_laursen's blog post
摘自并感谢peter_laursen 的博文
On OSX 10.7 (Lion), I created a file, /etc/my.cnf with the following contents:
在 OSX 10.7 (Lion) 上,我创建了一个包含以下内容的文件 /etc/my.cnf:
[mysqld]
max_allowed_packet = 12000000
And then stopped the mysql server:
然后停止了mysql服务器:
/usr/local/bin/mysql.server stop
When it automatically restarted I was able to execute my inserts.
当它自动重新启动时,我能够执行我的插入。
回答by Sire
Increasing max_allowed_packet to 12 MB (12000000) solved the problem for me when trying to import a 130 MB file.
在尝试导入 130 MB 文件时,将 max_allowed_packet 增加到 12 MB (12000000) 解决了我的问题。
Change the ini file or under Options File / Networking in MySQL Workbench (MySQL restart required).
更改 ini 文件或在 MySQL Workbench 中的 Options File / Networking 下(需要重启 MySQL)。
If you still get the error, try increasing even more (100 MB). Just remember to decrease it when you're done.
如果仍然出现错误,请尝试增加更多 (100 MB)。只要记住在完成后减少它。
回答by Amit Vujic
1) Change in MySql config file: # /etc/mysql/my.cnf
1) MySql 配置文件中的更改:# /etc/mysql/my.cnf
#section
#
[mysqld]
#
key_buffer = 32M
max_allowed_packet = 32M
thread_stack = 512K
thread_cache_size = 64
#
2) MySql deamon restart
2)MySql守护进程重启
/etc/init.d/mysql restart
Should resolve yours issues.
应该可以解决你的问题。