Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql determines whether to start the script

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report