Auto restart mysql in Linux server

linux

This is not a clean solution, it would obviously be better to avoid the problem in the first place. Anyway, I am not sure how CentOS manages services but I think it uses service. If so, you can check if the mysql service is running with

/sbin/service mysql status
This command will exit successfully if mysql is running and return a non 0 exit status if i is not. You can therefore start the service if it is not running with this command:

/sbin/service mysql status || service mysql start
You can add this line to /etc/crontab to launch thes command every minute:

* * * * * /sbin/service mysql status || service mysql start

How to add to cronjob?

Step 1: login to console server

Use this command to edit list cronjob in your server:

crontab -e

Step 2: Paste above line to last line.Auto restart mysql in Linux server

You can see cron list by this command:

crontab -l

Auto restart mysql in Linux server

2 thoughts on “Auto restart mysql in Linux server

Comments are closed.