多实例MySQL启动脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多实例MySQL启动脚本相关的知识,希望对你有一定的参考价值。
开发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
本文出自 “BidongWeb” 博客,请务必保留此出处http://jibidong.blog.51cto.com/11717102/1933516
以上是关于多实例MySQL启动脚本的主要内容,如果未能解决你的问题,请参考以下文章