開(kāi)發(fā)MySQL多實(shí)例啟動(dòng)腳本:
專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)制作、網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)嘉祥免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000+企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
已知mysql多實(shí)例啟動(dòng)命令為:mysqld_safe–defaults-file=/data/3306/my.cnf &
停止命令為:mysqladmin -u root -p123456 -S /data/3306/mysql.sock shutdown
要求:用函數(shù),case語(yǔ)句、if語(yǔ)句等實(shí)現(xiàn)。
#!/bin/sh [ -f /etc/init.d/functions ]&&. /etc/init.d/functions||exit #Define Variables Port=$1 Mysql_user=root Mysql_sock=/data/${Port}/mysql.sock Path=/application/mysql/bin RETVAL=0 #Define Start Function start() { if [ ! -e "$Mysql_sock" ];then /bin/sh $Path/mysqld_safe --defaults-file=/data/${Port}/my.cnf 2>&1 >/dev/null & RETVAL=$? if [ $RETVAL -eq 0 ];then action "Starting $Port MySQL..." /bin/true else action "Starting $Port MySQL..." /bin/false fi else echo "$Port MySQL is Running..." fi return $RETVAL } #Define Stop Function stop() { if [ ! -e "$Mysql_sock" ];then echo "$Port MySQL is Stopped..." else read -p "Please Input $Port MySQL Password:" PWD Mysql_pwd=$PWD $Path/mysqladmin -u ${Mysql_user} -p${Mysql_pwd} -S /data/${Port}/mysql.sock shutdown RETVAL=$? if [ $RETVAL -eq 0 ];then action "Stopping $Port MySQL..." /bin/true else action "Stopping $Port MySQL..." /bin/false fi fi return $RETVAL } case "$2" in start) start RETVAL=$? ;; stop) stop RETVAL=$? ;; restart) stop sleep 3 start RETVAL=$? ;; *) echo -e "USAGE:$0 {3306|3307|3308} {start|stop|restart}" RETVAL=2 ;; esac exit $RETVAL