标签:命令 shu stop ase 案例 art scripts roc 启动
企业案例:开发mysql多实例启动脚本:[root@jason ~]# ls -ld /data/3306/
drwxr-xr-x 3 mysql mysql 4096 Oct 9 13:28 /data/3306/
1)已知mysql多实例启动命令为:
mysql_safe --default-file=/data/3306/my.cnf &
2)停止命令为:
mysqladmin -uroot -poldboy123 -S /data/3306/mysql.sock shutdown
注:其实启动脚本可以更简化,当然作者本人展示的以谨慎的编写来展示脚本
MySQL多实例启动脚本展示:
[root@jason ~]# cat /data/3306/mysql
#!/bin/sh
#kconfig:2345 13 15
#This is mysql start|stop|restart scripts.
#-------------------------------------
#Author:jason
#QQ:760966297
#mile:jasonminghao@163.com
#-------------------------------------
[ -f /etc/init.d/functions ]&& . /etc/init.d/functions
Mysql_User=root
Mysql_Password=oldboy123
Mysql_Port=3306
Mysql_Path=/data/${Mysql_Port}
Mysql_Sock=/data/${Mysql_Port}/mysql.sock
Cmd_Path=/application/mysql/bin
fun_usage(){
echo "USAGE $0:{start|stop|restart}"
exit 1
}
fun_start(){
if [ -e $Mysql_Sock ];then
action "MySQL is running." /bin/false
else
/bin/sh ${Cmd_Path}/mysqld_safe --defaults-file=$Mysql_Path/my.cnf 2>&1 >/dev/null & #Mysql start
sleep 2
netstat -lntup |grep 3306 >/dev/null #acheck mysql process
[ $? -eq 0 ]&&action "Mysql start successfully." /bin/true || action "Mysql startup failure." /bin/false
fi
}
fun_stop(){
if [ ! -e $Mysql_Sock ];then
action "MyySQL is not run." /bin/false
exit 2
else
${Cmd_Path}/mysqladmin -u${Mysql_User} -p${Mysql_Password} -S ${Mysql_Sock} shutdown
netstat -lntup |grep 3306 >/dev/null
[ $? -ne 0 ]&& action "Mysql stop is successfully." /bin/true || action "Mysql stop is failure." /bin/false
fi
}
fun_restart(){
fun_stop
sleep 2
fun_start
netstat -lntup |grep 3306 >/dev/null
[ $? -eq 0 ]&& action "Mysql restart is successfully." /bin/true || action "Mysql restart is failure." /bin/false
exit 103
}
case $1 in
start)
fun_start
;;
stop)
fun_stop
;;
restart)
fun_restart
;;
*)
fun_usage
;;
esac
脚本测试:
[root@jason ~]# /data/3306/mysql start
Mysql start successfully. [ OK ]
[root@jason ~]# /data/3306/mysql stop
Mysql stop is successfully. [ OK ]
[root@jason ~]# /data/3306/mysql restart #<==这里因为是在代码中定义了进程不存在就会提示
MyySQL is not run. [FAILED]
[root@jason ~]# /data/3306/mysql start
Mysql start successfully. [ OK ]
[root@jason ~]# /data/3306/mysql restart
Mysql stop is successfully. [ OK ]
Mysql start successfully. [ OK ]
Mysql restart is successfully. [ OK ]
标签:命令 shu stop ase 案例 art scripts roc 启动
原文地址:http://blog.51cto.com/12643266/2298643