Automatically restart MySQL on Centos, Ubuntu

Automatically restart MySQL on Centos, Ubuntu

Hey guys!
If your facing MySQL service down problem. But you would like MySQL automatic restart if it, for any reason stops.

Maybe you have small server that is reason your MySQL server process stops.

But this tutorial help you out from automatic MySQL stop problem.

So let start it.

You need to check MySQL or Mariadb.

Mysql command:

Service mysqld status

Mariadb command:

Service mariadb status

You need add a Cron job in your linux that automatic check when mysql service stop its automatic restart it.

Run command to open Crontab if you don’t want to use this editor then you can use nano editor. click here to run Crontab as nano editor.

crontab -e

for Mysql:

Every mint check

* * * * /sbin/service mysqld status || service mysqld restart

Every 5 mint check:

*/5 * * * * /sbin/service mysqld status || service mysqld restart

For Mariadb:

Every mint check

* * * * * /sbin/service mariadb status || service mariadb restart

Every 5 mint check

*/5 * * * * /sbin/service mariadb status || service mariadb restart

Note: only add one line which you want to check every mint or every 5 mint. then save it in Crontab.

its automatic restart when its down.

COMMENTS