Automatic Reconnection of MySQL Connections in Active Record
MySQL per default kills inactive connections after 8 hours. This timeout can be changed in my.cnf by setting wait_timeout value.
If you use Active Record and your program tries to use persistent connection after 8 hours of inactivity, you are likely to see the following error:
1 Mysql::Error: MySQL server has gone away ...
This is not a problem if Active Record is used within Rails controller actions. Rails verifies and reconnects inactive connections before invoking an action.
If you use Active Record outside Rails or at least outside controller actions you have to verify connections on your own before executing a database statement. This can be done with the following code: