修复“MySQL服务器已经消失”的错误

我在使用mysql服务器时遇到了麻烦(正如你所看到的,我的服务器默认帐户也是如此,那是其他历史logging)。 我在查询时出现“Mysql server has gone away ..”错误,我正在使用Debian Lenny,MySQL版本5.0.51a-24 + lenny2-log,这里是my.cnfconfiguration

[client] port = 3306 socket = /var/run/mysqld/mysqld.sock # Here is entries for some specific programs # The following values assume you have at least 32M ram # This was formally known as [safe_mysqld]. Both versions are currently parsed. [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp language = /usr/share/mysql/english skip-external-locking # # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 0.0.0.0 # # * Fine Tuning # wait_timeout = 28800 net_read_timeout = 60 net_write_timeout = 60 key_buffer = 384M max_allowed_packet = 64M thread_stack = 128K thread_cache_size = 8 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover = BACKUP #max_connections = 100 table_cache = 4096 sort_buffer = 2M read_buffer = 2M read_rnd_buffer = 64M myisam_sort_buffer_size = 64M #thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 64M query_cache_size = 32M # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. #log = /var/log/mysql/mysql.log # # Error logging goes to syslog. This is a Debian improvement :) # # Here you can see queries with especially long duration log_slow_queries = /var/log/mysql/mysql-slow.log long_query_time = 2 #log-queries-not-using-indexes # # The following can be used as easy to replay backup logs or for replication. # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name # # * BerkeleyDB # # Using BerkeleyDB is now discouraged as its support will cease in 5.1.12. skip-bdb # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! # You might want to disable InnoDB to shrink the mysqld process by circa 100MB. #skip-innodb # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [mysqldump] quick quote-names max_allowed_packet = 32M [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer = 16M # # * NDB Cluster # # See /usr/share/doc/mysql-server-*/README.Debian for more information. # # The following configuration is read by the NDB Data Nodes (ndbd processes) # not from the NDB Management Nodes (ndb_mgmd processes). # # [MYSQL_CLUSTER] # ndb-connectstring=127.0.0.1 # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ 

有什么我可以调整停止这个错误?

谢谢!

我看到两种可能性:

1. PHP花费很长时间:

如果您使用的是PHP,执行时间可能会比MySQL的超时时间长。 你可能想检查net_read_timeoutnet_write_timeout对PHP的max_execution_time 。 如果PHP的执行时间超过60,那么MySQL可能会断开连接。

2.重载服务器

由于你的wait_timeoutvariables是8小时(28800秒),你可能会被闲置的MySQL连接困扰。 使用show processlist查询来查看有多less空闲线程正在运行。 如果你有很多空闲线程,那么你可能需要降低wait_timeout指令。 我目前在生产Web服务器上使用的值是60(没有人抱怨过)。

无论如何,MySQL显然需要一些设置调整。 networking上有很多关于MySQL调优的文章。

“消失”的信息是服务器厌倦了等待并closures连接的信号。

你应该可以通过打开一个新的连接来唤醒它。

“MySQL已经消失”意味着你的Web应用程序无法访问MySQL服务器。 这将表明它已经closures或无法访问。 您可以使用另一个Web应用程序phpMyAdmin或命令行选项“show processlist”来查看。 看看MySQL服务器在内部发生了什么。

如果您的服务器没有足够的内存供MySQL运行,那么这种情况很常见,请检查您的内存使用情况,并确保您的设置足够多。