MySQL determines whether to start the script

Source: Internet
Author: User

#!/bin/bash

#By: sadoc.blog.51cto.com


. /etc/rc.d/init.d/functions

Myuser=root

Mypass= "123456"

Mysock=/var/lib/mysql/mysql.sock

my_start= "Systemctl START mysqld.service"

Log_path=/tmp/mysql

My_path=/usr/bin/mysql

days= ' Date +%f '

second= ' Date +%y/%m/%d-%h:%m:%s '

Starting= "${log_path}/start-$DAYS. LOG"

[-D $LOG _path] | | Mkdir-p $LOG _path

my_cmd= "$MY _path-u$myuser-p$mypass-s $MYSOCK"

$MY _cmd-e "select version (); >/dev/null 2>&1

If [$?-eq 0];then

Action "$SECOND----Mysql"/bin/true >> $LOG _path/my_status.log

Exit 0

Else

$MY _start >> $STARTING

Sleep 5;

$MY _cmd-e "select version (); >/dev/null 2>&1

If [$?-ne 0];then

For-down ' seq 5 '

Do

Systemctl Stop Mysqld.service >/dev/null 2>&1

[$?-ne 0] && break;

Sleep 2;

Done

$MY _start >> $STARTING

Fi

$MY _cmd-e "Select Version" >/dev/null 2>&1 && status= "restarted" | | Status= "Unkown"

echo "$SECOND------Mysql status is $Status" >> $LOG _path/my_status.log

Fi

MySQL determines whether to start the 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.