Linux Mysql启动脚本

Linux Mysql启动脚本

#/bin/bash
#init
Port=3306
MysqlUser="root"
MysqlPass="123456"
CmdPath="/application/mysql/bin"

#startup fnction
start()
{
    if [ `netstat -lnt|grep "$Port"|wc -l` -eq 0 ]
        then
            printf "Starting Mysql...\n"
            /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${Port}/my.conf2>&1 > /dev/null &
    else
        printf "Mysql is running...\n"
    fi
}

#stop function
stop()
{
    if [ ! `netstat -lnt|grep "$Port"|wc` -l -eq 0]
        then
            printf "Stopping Mysql...\n"
            ${CmdPath}/mysqladmin -u ${MysqlUser} -p${MysqlPass} -s /data/${Port}/mysql.sock shutdown
    else
        printf "Mysql is stopped...\n"
    fi
}

#restart funcation
restart()
{
    printf "Restarting Mysql...\n"
    stop
    sleep 2
    start
}

case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    restart
    ;;
*)
    printf "Usage: $0 {start|stop|restart}\n"
esac

你可能感兴趣的:(Linux Mysql启动脚本)