我试图通过phpMyAdmin导入一个大的sql文件…但它一直显示错误
“MySql服务器已经消失”
怎么办呢?
我试图通过phpMyAdmin导入一个大的sql文件…但它一直显示错误
“MySql服务器已经消失”
怎么办呢?
当前回答
如下所述:
Two most common reasons (and fixes) for the MySQL server has gone away (error 2006) are: Server timed out and closed the connection. How to fix: check that wait_timeout variable in your mysqld’s my.cnf configuration file is large enough. On Debian: sudo nano /etc/mysql/my.cnf, set wait_timeout = 600 seconds (you can tweak/decrease this value when error 2006 is gone), then sudo /etc/init.d/mysql restart. I didn't check, but the default value for wait_timeout might be around 28800 seconds (8 hours). Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection. You can increase the maximal packet size limit by increasing the value of max_allowed_packet in my.cnf file. On Debian: sudo nano /etc/mysql/my.cnf, set max_allowed_packet = 64M (you can tweak/decrease this value when error 2006 is gone), then sudo /etc/init.d/mysql restart.
编辑:
注意,MySQL选项文件没有它们的命令作为注释可用(例如在php.ini中)。所以你必须在my.cnf或my.ini中输入任何更改/调整,并将它们放在mysql/data目录或任何其他路径下,在适当的选项组下,如[client], [myslqd]等。例如:
[mysqld]
wait_timeout = 600
max_allowed_packet = 64M
然后重新启动服务器。要得到它们的值,在mysql客户端中输入:
> select @@wait_timeout;
> select @@max_allowed_packet;
其他回答
对我来说,这个解决方案不可行,所以我执行了
SET GLOBAL max_allowed_packet=1073741824;
在我的SQL客户端。
如果不能改变MYSql服务运行,你应该停止服务,并改变my.ini文件中的变量。
例如:
max_allowed_packet=20M
我用这个简短的/etc/mysql/my.cnf文件解决了我的问题:
[mysqld]
wait_timeout = 600
max_allowed_packet = 100M
如下所述:
Two most common reasons (and fixes) for the MySQL server has gone away (error 2006) are: Server timed out and closed the connection. How to fix: check that wait_timeout variable in your mysqld’s my.cnf configuration file is large enough. On Debian: sudo nano /etc/mysql/my.cnf, set wait_timeout = 600 seconds (you can tweak/decrease this value when error 2006 is gone), then sudo /etc/init.d/mysql restart. I didn't check, but the default value for wait_timeout might be around 28800 seconds (8 hours). Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection. You can increase the maximal packet size limit by increasing the value of max_allowed_packet in my.cnf file. On Debian: sudo nano /etc/mysql/my.cnf, set max_allowed_packet = 64M (you can tweak/decrease this value when error 2006 is gone), then sudo /etc/init.d/mysql restart.
编辑:
注意,MySQL选项文件没有它们的命令作为注释可用(例如在php.ini中)。所以你必须在my.cnf或my.ini中输入任何更改/调整,并将它们放在mysql/data目录或任何其他路径下,在适当的选项组下,如[client], [myslqd]等。例如:
[mysqld]
wait_timeout = 600
max_allowed_packet = 64M
然后重新启动服务器。要得到它们的值,在mysql客户端中输入:
> select @@wait_timeout;
> select @@max_allowed_packet;
如果需要很长时间才能失败,则扩大wait_timeout变量。
如果它马上失败,放大max_allowed_packet变量;如果它仍然不工作,确保命令是有效的SQL。我的书有未转义的引号,把一切都搞砸了。
此外,如果可行,可以考虑将单个SQL命令的插入数量限制为1000。您可以创建一个脚本,通过重新引入INSERT…每n个插入部分。
我更新了“max_allowed_packet”到1024M,但它仍然不能工作。结果发现我的部署脚本正在运行:
mysql --max_allowed_packet=512M --database=mydb -u root < .\db\db.sql
如果要这样做,请确保从命令行显式地指定一个更大的数字。