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

Rod*_*igo 4 mysql debian

我在 mysql 服务器上玩得很开心(正如你所看到的,我的 serverfault 帐户也是如此,那是其他历史记录)。我在查询中遇到错误“Mysql 服务器已经消失..”,我使用的是 Debian Lenny,MySQL 版本 5.0.51a-24+lenny2-log,这是 my.cnf 配置

[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/
Run Code Online (Sandbox Code Playgroud)

我可以调整以阻止此错误吗?

谢谢!

Sam*_*amK 5

我看到两种可能性:

1.PHP耗时长:

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

2.服务器超载

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

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