On Debian Sarge:
dpkg --list | grep mysql
ii libdbd-mysql-p 2.9006-1 A Perl5 database interface to the
MySQL data
ii libmysqlclient 3.23.56-3 LGPL-licensed client library for
MySQL datab
ii libmysqlclient 3.23.56-3 LGPL-licensed client development
files for M
ii libmysqlclient 4.0.24-10sarge mysql database client library
ii libmysqlclient 4.1.11a-4sarge mysql database client library
ii mysql-client-4 4.1.11a-4sarge mysql database client binaries
ii mysql-common-4 4.1.11a-4sarge mysql database common files (e.g.
/etc/mysql
ii mysql-server-4 4.1.11a-4sarge mysql database server binaries
MySQL times out connections after a period of inactivity. (see http://dev.mysql.com/doc/refman/5.0/en/gone-away.html) I think the
period defaults to 8 hours. You can see the same behavior if you open a
connection using the “mysql” command-line client, and leave it inactive
for a long time. The next query will fail at first (but the client
automatically reconnects).
Apparently, there are system variables (wait_timeout and
interactive_timeout) that you can set to increase the timeout. I’ve
never had to do this from Rails, though, so I’m not sure of the
procedure. In our case, we have a monitoring script that hits our site
and database periodically to make sure it’s all still up, and that has
the side effect of keeping the mysql connections alive.
Everythings works great, but after a long inactive period (say one
night),
the first 3 connections allways get an Error 500
Excerpt from production.log:
…
Rendering authentication/login
Completed in 0.00301 (332 reqs/sec) | Rendering: 0.00279 (92%) | DB:
0.00000(0%) | 200 OK
[ http://myapp/authentication/login ]
Mysql::Error: MySQL server has gone away: SELECT * FROM sessions WHERE
(session_id = ‘875b6a6dff4de7e8bb2f7709cf9c31db’) LIMIT 1
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.