A simple MySQL service detection startup script

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.