MySQL启动脚本

今天在公司,上午搞了一个小时,MySQL单实例启动脚本搞定。

[root@mysql-6 scripts]# cat test3.sh 
#!/bin/bash
RETVAL=0
. /etc/init.d/functions
basedir=/application/mysql-5.5.32/bin
datadir=/application/mysql-5.5.32/data
PSD=123.com
 
hostname=`hostname`
menu(){
cat <<END
======================
    1.start
    2.stop
    3.restart
    4.exit
======================
END
}
start(){
     if [ -f ${datadir}/${hostname}.pid ]
        then
           action "MySQL running..." /bin/false
        else
           ${basedir}/mysqld_safe --defaults-file=/etc/my.cnf --user=root >/dev/null 2>&1 &
           sleep 2
           action "stutting start MySQL" /bin/true 
     fi
}
stop(){
     if [ -f ${datadir}/${hostname}.pid ]
        then
           ${basedir}/mysqladmin -uroot -p${PSD} shutdown
           sleep 2
           action "MySQL stoping..." /bin/true 
        else
           action "MySQL stoping..." /bin/false
     fi
}
restart(){
     if [ -f ${datadir}/${hostname}.pid ]
         then
            ${basedir}/mysqladmin -uroot -p${PSD} shutdown
            action "MySQL stop..." /bin/true
            sleep 2
            ${basedir}/mysqld_safe --defaults-file=/etc/my.cnf --user=root >/dev/null 2>&1 &
            sleep 2
            action "MySQL start..." /bin/true
         else
            action "MySQL stop..." /bin/false
            ${basedir}/mysqld_safe --defaults-file=/etc/my.cnf --user=root >/dev/null 2>&1 &
            sleep 2
            action "MySQL start..." /bin/true
     fi
return $RETVAL
}
exit(){
     exit 1
}
main(){
while true
do
     menu
     read -p " MySQL masterserver :" men
     case "$men" in
        start)
           start
           RETVAL=$?
           ;;
        stop)
           stop
           RETVAL=$?
           ;;
        restart)
           restart
           RETVAL=$?
           ;;
        exit)
           exit
           ;;
        *)
           printf "choice menus error {start|stop|restart}"
           exit 1
     esac
done
exit $RETVAL
}
main

[root@mysql-6 scripts]# sh test3.sh
======================
    1.start
    2.stop
    3.restart
    4.exit
======================
 MySQL masterserver :start
MySQL running... [FAILED]
======================
    1.start
    2.stop
    3.restart
    4.exit
======================
 MySQL masterserver :stop
MySQL stoping... [  OK  ]
======================
    1.start
    2.stop
    3.restart
    4.exit
======================
 MySQL masterserver :start
stutting start MySQL [  OK  ]
======================
    1.start
    2.stop
    3.restart
    4.exit
======================
 MySQL masterserver :restart
MySQL stop... [  OK  ]
MySQL start... [  OK  ]
======================
    1.start
    2.stop
    3.restart
    4.exit
======================
 MySQL masterserver :exit

[root@mysql-6 scripts]#

 

我相信,我行的。能力与年龄无关--新华德瑞-运维处 老大 方小华教诲-虽然只有短短相处几天,但您很幽默,从毕业走来,从好多人身上学到很多东西。比较让自己成长的就是在联龙博通的日子吧,虽然每个月扣工资扣的还是心里不爽

本文出自 “晴空” 博客,谢绝转载!

你可能感兴趣的:(action,running,false)