#!/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 in `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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。