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.
#!/bin/sh[ -f /etc/init.d/functions ]&&. /etc/init.d/functions| | exit#define variablesport=$1mysql_user=rootmysql_sock=/data/${port}/mysql.sockpath=/application/mysql/ Binretval=0#define start functionstart () { 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 functionstop () { 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 "$" 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 ;; esacexit $RETVAL
This article is from the "Bidongweb" blog, make sure to keep this source http://jibidong.blog.51cto.com/11717102/1933516
Multi-instance MySQL startup script