专业规范的mysql启停脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了专业规范的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启停脚本的主要内容,如果未能解决你的问题,请参考以下文章
Linux下Dialog+Shell三层目录专业规范跳板机脚本
在 MySQL 中出现 ERROR 1701、ERROR 1452 和 ERROR 1305 错误 - 需要一些专业知识