#bin/bash
#author merci
function mysql_start(){
id=`ps -ef | grep 'mysql' | grep -v 'grep'`
if [ ! -n "$id" ]
then
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=root &
exit 0
else
echo -e "mysql already running !"
fi
}
function mysql_stop(){
id=`ps -ef | grep 'mysql' | grep -v 'grep'` | awk '{print $2}'
if [ ! -n "$id" ]
then
echo -e "mysql already stopping !"
else
for pid in $id
do
kill -9 $pid
echo -e "close process pid :$pid"
done
fi
}
echo -e "1. start mysql service"
echo -e "2. stop mysql service"
read -p "please choose id:" x
case $x in
1)
mysql_start
;;
2)
mysql_stop
;;
*)
echo "please input id !!!"
;;
esac
转载于:https://blog.51cto.com/huangmanyao/1928025