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 [$Port]" /bin/true else action "Start MySQL [$Port]" /bin/false fi else echo "MySQL $Port 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[$Port]" /bin/true else action "Stop MySQL[$Port]" /bin/false fi else echo "MySQL [$Port] is not running" exit 1 fi return $RETVAL } status(){ if [ -f "$Pid" ];then echo "MySQL [$Port] is running" else echo "MySQL [$Port] 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
转载于:https://blog.51cto.com/11576296/2397210