Mysql判断是否启动脚本
#!/bin/bash
创新互联公司提供网站设计制作、成都网站建设、网页设计,品牌网站设计,1元广告等致力于企业网站建设与公司网站制作,十载的网站开发和建站经验,助力企业信息化建设,成功案例突破上千家,是您实现网站建设的好选择.
#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判断是否启动脚本
网站URL:http://scyanting.com/article/jdpdpi.html