shell脚本:MySQL启动简易脚本
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
原文地址:http://mofansheng.blog.51cto.com/8792265/1704762