Automatic mysql-server start after MySQL server has gone away

Here is a cheap, quick and temporary solution to MySQL server has gone away message to ensure that mysql-server is running, that is automatically restarted after failure. This solution should be considered as temporary as it is in your best interest to investigate further your log files why your mysql server stopped and take appropriate steps to find long term solution. In the example below we use Debian Wheezy.

First install puppet:

# wget
# dpkg -i puppetlabs-release-wheezy.deb
# apt-get update
# apt-get install puppet

Create puppet manifest /root/mysql.pp. Feel free to use different location and file name:

# cat /root/mysql.pp
service { 'mysql':
	ensure => running,

Next, create a crontab task to run every minute:

# crontab -e

and add following line:

* * * * * /usr/bin/puppet apply /root/mysql.pp

The above will ensure that we check every minute whether mysql-server is running. If it is running we take no action and if its down puppet will start automatically.