I'm having a bad time with mysql server (and as you can see, with my serverfault account too, well, that's other history). I'm having errors in queries with "Mysql server has gone away..", I'm using Debian Lenny, MySQL version 5.0.51a-24+lenny2-log, and here is the my.cnf config

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.
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

# * 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
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            =
# * 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
# 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.
# * 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.
# * 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

max_allowed_packet      = 32M

#no-auto-rehash # faster start of mysql but no tab completition

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).
# ndb-connectstring=

# * 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/

Is anything that can I tweak for stop this error?



I see two possibilities:

1. PHP taking long time:

If you are using PHP, the execution time may be longer than MySQL's timeouts. You may want to check net_read_timeout and net_write_timeout against PHP's max_execution_time. If PHP's execution time is longer than 60, then MySQL might disconnect.

2. overloaded server

Since your wait_timeout variable is 8 hours (28800 seconds) You may be bothered by idle MySQL connections. Use the show processlist query to see how much idle threads are running. If you have a lot of idle threads then you might want to lower the wait_timeout directive. I am currently using a value of 60 on production web servers (and nobody has complained yet).

Anyway MySQL obviously needs some settings adjustments. There are a lot of articles around the web talking about MySQL tuning.

|improve this answer|||||

The 'gone away' message is a sign the server got tired of waiting and closed the connection.

You should be able to wake it up by opening a new connection.

|improve this answer|||||

'MySQL has gone away' means that your web app can not reach the MySQL server. It would indicate that it is down or unreachable. You can check with another web app, phpMyAdmin or the command line option 'show processlist;' to see what is going on internally with the MySQL server.

If your server does not have enough memory for MySQL to run it is common for it to die out like that, check your memory usage and ensure you have enough per your settings.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.