shell脚本编写MySQL建议简易启动脚本,练习使用变量,函数,case语句等知识;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
[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
|
执行结果如下图所示:
本文转自 模范生 51CTO博客,原文链接:http://blog.51cto.com/mofansheng/1704762如需转载请自行联系原作者