您好,登錄后才能下訂單哦!
開發mysql多實例啟動腳本:
已知mysql多實例啟動命令為:mysqld_safe–defaults-file=/data/3306/my.cnf &
停止命令為:mysqladmin -u root -p123456 -S /data/3306/mysql.sock shutdown
要求:用函數,case語句、if語句等實現。
#!/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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。