39

我使用 Wampserver 2.0 版。当我尝试通过 MySQL 查询浏览器或 PHPMyAdmin 导入 sql 文件时,我收到以下错误。

Error 2006: MySQL Server has gone away.

文件大小为 54,528 KB。

在 C:\wamp\bin\mysql\mysql5.1.30\my.ini 中,我在 [mysqldump] 和 [wampmysqld] 中将 max_allowed_pa​​cket 设置为 100M。我在 my.ini 中找不到 wait_timeout 变量。有什么办法可以解决这个问题吗?供您参考,我在下面给出了 my.ini 文件的内容。

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is C:\mysql\data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[wampmysqld]
port        = 3306
socket      = /tmp/mysql.sock
skip-locking
key_buffer = 16M
max_allowed_packet = 100M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
basedir=c:/wamp/bin/mysql/mysql5.1.30
log-error=c:/wamp/logs/mysql.log
datadir=c:/wamp/bin/mysql/mysql5.1.30/data

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
# 
#skip-networking

# Disable Federated by default
skip-federated

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id   = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Point the following paths to different dedicated disks
#tmpdir     = /tmp/     
#log-update     = /path-to-dedicated-directory/hostname

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = C:\mysql\data/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = C:\mysql\data/
#innodb_log_arch_dir = C:\mysql\data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 100M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld]
port=3306
4

8 回答 8

63

我在 Windows 上使用 XAMPP 并且遇到了同样的问题。我以为是超时变量,但它是max_allowed_packet.

这已经解决了它:

# note the change was made at this section
[mysqld] 
port= 3306
socket= "/xampp/mysql/mysql.sock"
basedir="/xampp/mysql" 
tmpdir="/xampp/tmp" 
datadir="/xampp/mysql/data"
skip-locking
key_buffer = 16M
# it was 1M by default
max_allowed_packet = 2M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

此配置文件位于«XAMPP 安装目录, C:\XAMPP 默认情况下»\mysql\bin\my.ini

于 2010-07-13T14:19:36.763 回答
8

这可能是因为max_allowed_packet

文件中的更改my.ini/my.cnf[mysqld]在文件中包含下面的单行

max_allowed_packet=500M

完成后现在重新启动MySQL service。您可以像这样在 mysql 中看到它的当前值:

SHOW VARIABLES LIKE 'max_allowed_packet'

你可以在这里阅读http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html

于 2014-03-27T13:09:49.450 回答
5

我在 Windows 7 上使用 Xampp 1.7.7 也遇到了同样的问题。以下是修复它的内容:

  • 增加 mysql.connect_timeout 值:
    ;连接超时的最长时间(以秒为单位)。-1 表示没有限制
    http://php.net/mysql.connect-timeout
    mysql.connect_timeout = 10 ; 默认为 3

  • 尝试了我之前所做的,并遇到了另一个关于“max_allowed_pa​​cket”的问题。

  • 进入 mysql\bin\my.ini 并找到设置 max_allowed_pa​​cket = 1M,然后将其更改为 10M: max_allowed_pa​​cket = 10M ;默认是1M

希望这能有所帮助。

于 2012-05-26T02:41:36.830 回答
2

PhpMyAdmin 文档:

1.16 我无法上传大转储文件(内存、HTTP 或超时问题)。

从版本 2.7.0 开始,导入引擎已被重新编写,不应出现这些问题。如果可能,请将您的 phpMyAdmin 升级到最新版本以利用新的导入功能。

首先要检查(或要求您的主机提供商检查)是php.ini配置文件中的upload_max_filesize、memory_limit 和 post_max_size的值。所有这三个设置都限制了 PHP 可以提交和处理的最大数据大小。一位用户还说 post_max_size 和 memory_limit 需要大于 upload_max_filesize。

如果您的上传太大或您的托管服务提供商不愿意更改设置,则有几种解决方法:

查看 $cfg['UploadDir'] 功能。这允许人们通过 scp、ftp 或您喜欢的文件传输方法将文件上传到服务器。然后 PhpMyAdmin 能够从临时目录中导入文件。本文档的配置部分提供了更多信息。

在上传之前使用实用程序(例如 BigDump)拆分文件。我们不支持此应用程序或任何第三方应用程序,但知道用户已成功使用它。

如果您有 shell(命令行)访问权限,请使用 MySQL 直接导入文件。您可以通过在 MySQL 中发出“source”命令来执行此操作:source filename.sql。

于 2012-09-11T07:34:31.043 回答
1

对于那些使用 Mac OSX 的开发人员,您需要在“my.cnf”文件中将 max_allowed_pa​​cket 从 1M 更改为 10M。

max_allowed_packet = 10M

您可能会在以下位置之一找到文件“my.cnf”:

  1. /etc/my.cnf(MAVERICKS 用户最可能的位置)
  2. /etc/mysql/my.cnf
  3. SYSCONFDIR/my.cnf
  4. $MYSQL_HOME/my.cnf
  5. defaults-extra-file(使用 --defaults-extra-file=path 指定的文件,如果有)
  6. ~/.my.cnf
于 2014-03-14T03:14:01.317 回答
1

MySQL错误2006解决步骤:

  1. 编辑位于“:\xampp\mysql\bin\”的“my.ini”文件。
  2. 在 my.ini 文件中,通过增加值来编辑“max_allowed_pa​​cket”。
    • XAMPP 默认值为 1M。我把它更新到10M。
  3. 保存 my.ini 文件。
  4. 在 XAMPP 中重新启动 MySQL 和 Apache 服务器。
于 2014-03-27T10:44:49.247 回答
0

如果增加内存大小的答案对您不起作用,请检查您的代码是否存在无限循环。

这就是我的代码中的内容,无论我将其增加到什么,都会耗尽我的记忆。堆栈跟踪提供了很好的线索,确保调试已打开,至少在本地!

于 2015-05-02T07:26:33.053 回答
0

我在将 Magento 从版本 x 更新到 y 时注意到了这个错误。查看日志,我发现表中有问题。

[错误] databaseabc /core_url_rewrite 的索引 UNQ_DH_CORE_URL_REWRITE_REQUEST_PATH_STORE_ID 在 InnoDB 中有 2 列唯一,但 MySQL 要求 3 列的统计信息。您是否混淆了来自不同安装的 .frm 文件?见http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html

修复此表解决了该问题。在我的情况下,我可以截断表,因为它是一个可以再次生成的索引。

于 2014-08-06T11:19:51.417 回答