您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
开发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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。