专业规范的mysql启停脚本

2019-08-23

专业规范的mysql启停脚本

#!/bin/sh
#######################################################
#ShellName:mysql启停脚本 #
#Author:zkg #
#Created Time:2019-08-23 #
#Blog Address:https://blog.51cto.com/1009516 #
#######################################################

#调用系统函数库
. /etc/init.d/functions
#定义路径变量
BASEDIR=/data/mysql
LOCK_FILE_PATH=/var/lock/subsys
LOCK_FILE=$LOCK_FILE_PATH/mysql
MYSQL_PID_FILE_PATH="$BASEDIR/uname -n.pid"

start(){
echo "Starting Mysql"
if [ -x $BASEDIR/bin/mysqld_safe ];then
$BASEDIR/bin/mysqld_safe &>/dev/null &
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "SUCCESS!!! start mysqld" /bin/true
if [ -w $LOCK_FILE_PATH ];then
touch $LOCK_FILE
fi
return $RETVAL
else
action "ERROR!!! start mysqld failed" /bin/false
fi
else
action "Couldn‘t find MySQL server ($BASEDIR/bin/mysqld_safe)" /bin/false
fi
}
stop(){
mysql_pid=cat $MYSQL_PID_FILE_PATH
if ( kill -0 $mysql_pid 2>/dev/null)
then
echo "Stopping Mysql"
kill -9 $mysql_pid
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "SUCCESS!!! stop mysqld" /bin/true
if [ -f $LOCK_FILE ];then
rm -f $LOCK_FILE
fi
return $RETVAL
else
action "ERROR!!! stop mysqld failed" /bin/false
fi
else
action "MySQL server process mysqld_pid is not running!" /bin/false
rm -f $MYSQL_PID_FILE_PATH
fi
}

case $1 in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart)
stop
sleep 2
start
RETVAL=$?
;;
*)
echo "Usage:$0 {start|stop|restart}"
RETVAL=$?
;;
esac
exit $RETVAL

专业规范的mysql启停脚本

专业规范的mysql启停脚本

原文地址:https://blog.51cto.com/1009516/2431976