MySQL 启动脚本-chenliangC

Windows Windows 2个月前 (08-15) 5次浏览 未收录 0个评论 扫描二维码

1.1 部署路径

MySQL程序部署路径:/data/apps/mysql

MySQL实例部署路径:/data/mysql/3306/

MySQL实例PID路径:/data/mysql/3306/mysql.pid

MySQL实例sock路径:/data/mysql/3306/mysql.sock

MySQL配置文件路径:/data/mysql/3306/my.cnf

1.2 脚本内容

#!/bin/bash
#
#?Load?os?variables
source?/etc/bashrc
source?/etc/profile

#?Define?variables
RETVAL=0
Port=3306
User=root
Pass=chenliang
Pid=/data/mysql/3306/mysql.pid
Sock=/data/mysql/3306/mysql.sock
My=/data/mysql/3306/my.cnf
Path=/data/apps/mysql/bin

#?Determine?the?user?to?execute
if?[?$UID?-ne?$RETVAL?];then
??echo?"Must?be?root?to?run?scripts"
??exit?1
fi

#?Load?the?local?functions
[?-f?/etc/init.d/functions?]?&&?source?/etc/init.d/functions

#?Define?functions
start(){
?????if?[?!?-f?"$Pid"?];then
??????$Path/mysqld_safe?--defaults-file=$My?>/dev/null?2>&1?&
??????RETVAL=$?
??????if?[?$RETVAL?-eq?0?];then
????????action?"Start?MySQL?[3306]"?/bin/true
???????else
????????action?"Start?MySQL?[3306]"?/bin/false
??????fi
?????else
??????echo?"MySQL?3306?is?running"
??????exit?1
????fi
????return?$RETVAL
}

stop(){
?????if?[?-f?"$Pid"?];then
??????$Path/mysqladmin?-u$User?-p$Pass?-S?$Sock?shutdown?>/dev/null?2>&1
??????RETVAL=$?
??????if?[?$RETVAL?-eq?0?];then
????????action?"Stop?MySQL[3306]"?/bin/true
???????else
????????action?"Stop?MySQL[3306]"?/bin/false
??????fi
?????else
??????echo?"MySQL?[3306]?is?not?running"
??????exit?1
?????fi
?????return?$RETVAL
}

status(){
??????if?[?-f?"$Pid"?];then
????????echo?"MySQL?[3306]?is?running"
???????else
???????echo?"MySQL?[3306]?is?not?running"
??????fi
??????return?$RETVAL
}

#?Case?call?functions
case?"$1"?in
??start)
????????start
????????RETVAL=$?
????????;;
??stop)
????????stop
????????RETVAL=$?
????????;;
??restart)
????????stop
????????sleep?5
????????start
????????RETVAL=$?
????????;;
??status)
????????status
????????RETVAL=$?
????????;;
??*)
??????????echo?"USAGE:$0{start|stop|restart|status}"
???????????exit?1
esac

#?Scripts?return?values
exit?$RETVAL
喜欢 (0)
[]
分享 (0)
关于作者:
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址