mysqld disconnects and mod doesn't auto-reconnect
Connected to a local mysqld trough a unix socket, we get this error when mod_mysql_vhost is trying to lookup the hostname:
2006-02-11 15:11:28: (mod_mysql_vhost.c.349) MySQL server has gone away
We have restarted mysqld and can access (and do queries) over the very same socket using php through mod_php/apache.
Restarting lighttpd solved the problem.
-- rasmus at flajm dot se
Updated by Anonymous almost 14 years ago
Maybe this could be a solution...
From the MySQL API manual:
"Note that upon connection, mysql_real_connect() sets the reconnect flag (part of the MYSQL structure) to a value of 1 in versions of the API older than 5.0.3, or 0 in newer versions. A value of 1 for this flag indicates that if a statement cannot be performed because of a lost connection, to try reconnecting to the server before giving up. As of MySQL 5.0.13, you can use the MYSQL_OPT_RECONNECT option to mysql_options() to control reconnection behavior."
I have tested to do this right before mysql_real_connect() in mod_mysql_vhost.c (somewhere around row 255, 1.4.13). It seems to works for me.
my_bool reconnect = 1;
mysql_options(s->mysql, MYSQL_OPT_RECONNECT, &reconnect);
Probably there must be some code to recognize which version of the MySQL library that is in use.
Updated by Anonymous over 13 years ago
Replying to email@example.com:
I have tested to do this right before mysql_real_connect() in mod_mysql_vhost.c
(somewhere around row 255, 1.4.13). It seems to works for me.
Thanks Patrik, based on your description I created a .diff. Compile tested for now, hopefully works as well as you said:
--- lighttpd-1.4.x/src/mod_mysql_vhost.c.ORIG 2007-05-02 17:50:58.000000000 +0100 +++ lighttpd-1.4.x/src/mod_mysql_vhost.c 2007-05-02 17:52:50.000000000 +0100 @@ -256,2 +256,6 @@ SERVER_FUNC(mod_mysql_vhost_set_defaults + /* http://trac.lighttpd.net/trac/ticket/518 */ + my_bool reconnect = 1; + mysql_options(s->mysql, MYSQL_OPT_RECONNECT, &reconnect); + if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass),
Also available in: Atom