单实例
启动:mysqld_safe --user=mysql &
停止:mysqladmin -u root -proot shutdown
开发脚本
#!/bin/bash
#chkconfig: 2345 30 50
#Date:2017-6-29
#Author:xcn(baishuchao@yeah.net)
#version Ultimates
PID="/var/run/mysqld/mysqld.pid"
user="root" #定义用户名密码
pass="root"
path="/usr/bin"
. /etc/init.d/functions
function usage(){
echo "$0 {start|stop|restart}"
exit 1
}
[ $# -ne 1 ] && usage #当$#号等于1则执行usage函数
#start_mysql
function start_mysql( ){
if [ ! -f $PID ]
then
$path/mysqld_safe --user=mysql & >/dev/null 2>&1 #一定要全路径以免出错
if [ $? -eq 0 ]
then
action "start mysql" /bin/true
else
action "start mysql erro" /bin/false
fi
else
echo "mysqld is running"
fi
}
#stop_mysql
function stop_mysql( ){
$path/mysqladmin -u $user -p$pass shutdown >/dev/null 2>&1
if [ $? -eq 0 ]
then
action "stop mysql" /bin/true
else
action "stop mysql erro" /bin/false
fi
}
#传参判断执行
if [ "$1" == "start" ]
then
start_mysql
elif [ "$1" == "stop" ]
then
stop_mysql
elif [ "$1" == "restart" ]
then
stop_mysql
start_mysql
else #不符合以上则打印usage函数
usage
fi