码迷,mamicode.com
首页 > 数据库 > 详细

Mysql判断是否启动脚本

时间:2017-04-26 19:16:40      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:mysql   启动   脚本   

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

Mysql判断是否启动脚本

标签:mysql   启动   脚本   

原文地址:http://sadoc.blog.51cto.com/12189157/1919656

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!