十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
开发MySQL多实例启动脚本:
专注于为中小企业提供网站设计制作、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业嘉祥免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
已知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