修正“MySQL 伺服器已消失”錯誤

修正“MySQL 伺服器已消失”錯誤

我在 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_timeoutnet_write_timeout對照 PHP 的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 伺服器。這表明它已關閉或無法訪問。您可以使用另一個網頁應用程式檢查,php我的管理者或命令列選項“show processlist;”查看 MySQL 伺服器內部發生了什麼情況。

如果您的伺服器沒有足夠的記憶體來運行 MySQL,那麼它很常見,請檢查您的記憶體使用情況並確保您的設定有足夠的記憶體。

相關內容