我试图通过phpMyAdmin导入一个大的sql文件…但它一直显示错误

“MySql服务器已经消失”

怎么办呢?


当前回答

如果你使用默认值运行,那么你有很多空间来优化你的mysql配置。

我建议的第一步是将max_allowed_packet增加到128M。

然后下载MySQL Tuning Primer脚本并运行它。它将为您的配置提供几个方面的建议,以获得更好的性能。

另外,还要在MySQL和PHP中调整超时值。

你要导入的文件有多大(文件大小),你能使用mysql命令行客户端而不是PHPMyAdmin导入文件吗?

其他回答

我得到一个类似的错误。要解决这个问题,只需打开my.ini文件,在第36行更改最大允许数据包大小的值。max_allowed_packet = 20M

如果你在XAMPP上工作,那么你可以修复MySQL服务器已经消失的问题。

打开my.ini文件 my.ini的位置是(D:\xampp\mysql\bin\my.ini)

修改以下变量值

max_allowed_packet = 64M
innodb_lock_wait_timeout = 500

如果增加max_allowed_packet没有帮助。

当我通过Sequel Pro将.sql文件导入我的数据库时,我得到了和你一样的错误。

在将max_allowed_packet提高到512M后,错误仍然存在,所以我在命令行中运行导入:

mysql --verbose -u root -p DatabaseName < MySQL.sql

它给出了以下错误:

ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled

我发现了一些有用的StackOverflow问题:

在从SQL转储恢复数据库时启用二进制模式 Mysql错误:ASCII '\0'当导入sql文件在linux服务器上

在我的情况下,我的.sql文件有点损坏。我们得到的MySQL转储是两个zip文件,需要连接在一起,然后解压缩。我认为解压一开始就中断了,留下了一些奇怪的字符和编码。获得一个新的MySQL转储并正确地解压缩它对我来说很有效。

只是想在这里添加这个,以防其他人发现增加max_allowed_packet变量没有帮助。

对我来说,这个解决方案不可行,所以我执行了

SET GLOBAL max_allowed_packet=1073741824;

在我的SQL客户端。

如果不能改变MYSql服务运行,你应该停止服务,并改变my.ini文件中的变量。

例如:

max_allowed_packet=20M

如下所述:

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;