多執行個體MySQL啟動指令碼

來源:互聯網
上載者:User

標籤:ret   lease   default   ini   rest   code   sleep   p12   mysql   

開發mysql多執行個體啟動指令碼:

已知mysql多執行個體啟動命令為:mysqld_safe–defaults-file=/data/3306/my.cnf &

停止命令為:mysqladmin -u root -p123456 -S /data/3306/mysql.sock shutdown

要求:用函數,case語句、if語句等實現。

 1 #!/bin/sh 2 [ -f /etc/init.d/functions ]&&. /etc/init.d/functions||exit 3 #Define Variables 4 Port=$1 5 Mysql_user=root 6 Mysql_sock=/data/${Port}/mysql.sock 7 Path=/application/mysql/bin 8 RETVAL=0 9 #Define Start Function10 start() {11   if [ ! -e "$Mysql_sock" ];then12     /bin/sh $Path/mysqld_safe --defaults-file=/data/${Port}/my.cnf 2>&1 >/dev/null &13     RETVAL=$?14     if [ $RETVAL -eq 0 ];then15         action "Starting $Port MySQL..." /bin/true16       else17         action "Starting $Port MySQL..." /bin/false18     fi19     else20       echo "$Port MySQL is Running..."21   fi22   return $RETVAL23 }24 25 #Define Stop Function26 stop() {27   if [ ! -e "$Mysql_sock" ];then28       echo "$Port MySQL is Stopped..."29     else30       read -p "Please Input $Port MySQL Password:" PWD31       Mysql_pwd=$PWD32       $Path/mysqladmin -u ${Mysql_user} -p${Mysql_pwd} -S /data/${Port}/mysql.sock shutdown33       RETVAL=$?34       if [ $RETVAL -eq 0 ];then35         action "Stopping $Port MySQL..." /bin/true36       else37         action "Stopping $Port MySQL..." /bin/false38       fi39   fi40   return $RETVAL41 }42 43 case "$2" in44   start)45         start46         RETVAL=$?47         ;;48   stop)49         stop50         RETVAL=$?51         ;;52   restart)53         stop54         sleep 355         start56         RETVAL=$?57         ;;58   *)59         echo -e "USAGE:$0 {3306|3307|3308} {start|stop|restart}"60         RETVAL=261         ;;62 esac63 exit $RETVAL

 

多執行個體MySQL啟動指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.