Multi-instance MySQL startup script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.