Objective: To monitor the survival status of MySQL and restart MySQL once it is monitored for MySQL down.
Script content:
/usr/local/mysql/bin/mysqladmin-uroot-psharpower ping >/dev/null 2>&1if [$?-ne 0]then/etc/init.d/m Ysql.server Restart >/dev/null echo "'/bin/date ' +%y%m%d%h:%m:%s ' mysql is restart ' >>/root/scripts/m Ysql_run.logfi
Use the crontab timed task to execute the script:
[Email protected]_mysql scripts]# CRONTAB-L*/2 * * * */bin/bash/root/scripts/mysql_ping.sh
Manual emulation off MSYQL, then 2 minutes interval, view cron execution Log "/var/log/cron" and script execution day
Chi "/root/scripts/mysql_run.log"
#cron执行日志 [[email protected]_mysql scripts]# tail -n 10 /var/log/cronjul 22 16:27:01 Master_mysql crontab[5818]: (Root) BEGIN EDIT (root) jul 22 16:27:07 Master_mysql crontab[5818]: (Root) REPLACE (root) jul 22 16:27:07 master_mysql crontab[5818]: (Root) END EDIT (root) jul 22 16:27:38 master_mysql crontab[5849]: (Root) LIST (root) jul 22 16:28:01 Master_mysql crond[3103]: (Root) RELOAD (cron/root) jul 22 16:28:01 master_mysql crond[5853]: (Root) CMD (/bin/bash /root/scripts/mysql_ping.sh) Jul 22 16:29:59 master_mysql crontab[6138]: (Root) LIST (root) jul 22 16:30:01 master_mysql crond[6140]: (Root) CMD (/bin/bash /root/scripts/mysql_ ping.sh) JUL 22 16:32:01&NBSp master_mysql crond[6394]: (Root) CMD (/bin/bash /root/scripts/mysql_ping.sh) Jul 22 16:34:01 master_mysql crond[6429]: (Root) CMD (/bin/bash /root/scripts/ mysql_ping.sh) #脚本执行日志 [[email protected]_mysql scripts]# cat mysql_run.log20140722 16:28:14 mysql is restart20140722 16:30:09 mysql is Restart20140722 16:34:08 mysql is restart
This will enable MySQL to automatically start when it stops serving.
This article is from the "Stenning Technology blog" blog, make sure to keep this source http://magic3.blog.51cto.com/1146917/1440963
A simple MySQL service detection startup script