MySQL connections don't reconnect after idle timeout
Tthis is a workaround I use and it works for me.
for explanations of the options below.
in /etc/my.cnf you can add this…
# vim /etc/my.cnf
# 3 day timeout in seconds
The default value for wait_timeout is 28800 which is 8 hours.
wait_timeout is for connections from TCP/IP.
I also found this.
Note:The suggested fix would be to trap error 2006 and immediately attempt to reconnect to the database.