我在使用 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/
我可以调整什么来停止此错误?
谢谢!
答案1
我看到两种可能性:
1. PHP 耗时较长:
如果您使用的是 PHP,则执行时间可能比 MySQL 的超时时间长。您可能需要检查net_read_timeout
PHPnet_write_timeout
的max_execution_time
。如果 PHP 的执行时间长于 60,则 MySQL 可能会断开连接。
2. 服务器过载
由于您的wait_timeout
变量是 8 小时(28800 秒),您可能会被空闲的 MySQL 连接所困扰。使用查询show processlist
查看有多少空闲线程正在运行。如果您有很多空闲线程,那么您可能需要降低指令wait_timeout
。我目前在生产 Web 服务器上使用的值是 60(目前还没有人抱怨)。
无论如何,MySQL 显然需要一些设置调整。网上有很多关于 MySQL 调优的文章。
答案2
“消失”消息表示服务器厌倦了等待并关闭了连接。
您应该能够通过打开新连接来唤醒它。
答案3
“MySQL 已消失”意味着您的 Web 应用无法访问 MySQL 服务器。这表明它已关闭或无法访问。您可以使用另一个 Web 应用进行检查,phpMyAdmin或使用命令行选项“show processlist;”查看 MySQL 服务器内部发生的情况。
如果您的服务器没有足够的内存来运行 MySQL,那么它通常会死机,请检查您的内存使用情况并确保您有足够的内存来设置。