#!/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