To develop a MySQL multi-instance startup script:
Known MySQL multi-instance start commands are: Mysqld_safe–defaults-file=/data/3306/my.cnf &
The Stop command is: mysqladmin-u root-p123456-s/data/3306/mysql.sock shutdown
Requirements: Implemented with functions, case statements, if statements, and so on.
1#!/bin/SH2[-f/etc/init.d/functions]&&. /etc/init.d/functions| |Exit3 #Define Variables4port=$15Mysql_user=Root6mysql_sock=/data/${port}/Mysql.sock7path=/application/mysql/bin8Retval=09 #Define Start FunctionTen start () { One if[!-E"$Mysql _sock"]; Then A/bin/SH$Path/mysqld_safe--defaults-file=/data/${port}/my.cnf2>&1>/dev/NULL& -Retval=$? - if[$RETVAL-eq0]; Then theAction"starting $Port MySQL ..."/bin/true - Else -Action"starting $Port MySQL ..."/bin/false - fi + Else - Echo "$Port MySQL is Running ..." + fi A return $RETVAL at } - - #Define Stop Function - Stop () { - if[!-E"$Mysql _sock"]; Then - Echo "$Port MySQL is Stopped ..." in Else -Read-p"Please Input $Port MySQL Password:"PWD toMysql_pwd=$PWD +$Path/mysqladmin-u ${mysql_user}-p${mysql_pwd}-s/data/${port}/Mysql.sock shutdown -Retval=$? the if[$RETVAL-eq0]; Then *Action"stopping $Port MySQL ..."/bin/true $ ElsePanax NotoginsengAction"stopping $Port MySQL ..."/bin/false - fi the fi + return $RETVAL A } the + Case " $" inch - start) $ Start $Retval=$? - ;; - stop) the Stop -Retval=$?Wuyi ;; the restart) - Stop Wu Sleep 3 - Start AboutRetval=$? $ ;; -*) - Echo-E"usage:$0 {3306|3307|3308} {Start|stop|restart}" -Retval=2 A ;; + Esac theExit $RETVAL
Multi-instance MySQL startup script