您的位置:首页 > 运维架构 > Shell

shell脚本:MySQL启动简易脚本

2015-10-21 10:12 441 查看
shell脚本编写MySQL建议简易启动脚本,练习使用变量,函数,case语句等知识;

[root@localhost baby]# cat mysql_function.sh
#!/bin/bash
. /etc/init.d/functions
path=/usr/local/mysql/bin/
function usage(){
echo "$0 {start|stop|restart}"
exit 1
}
[ $# -ne 1 ] && usage

function_mysql_start(){
$path/mysqld_safe --user=mysql &>/dev/null &
if [ $? -eq 0 ]
then
sleep 5
action "start mysql" /bin/true
else
action "start mysql" /bin/false
fi
}

function_mysql_stop(){
$path/mysqladmin -uroot shutdown &>/dev/null
if [ $? -eq 0 ]
then
action "stop mysql" /bin/true
else
action "stop mysql" /bin/false
fi
}

function_mysql_restart(){
function_mysql_stop
sleep 3
function_mysql_start
}

case $1 in
start)
function_mysql_start
;;
stop)
function_mysql_stop
;;
restart)
function_mysql_restart
;;
*)
printf "Usage:$0 {start|stop|restart}\n"
esac


执行结果如下图所示:



本文出自 “模范生的学习博客” 博客,请务必保留此出处http://mofansheng.blog.51cto.com/8792265/1704762
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: