1. #!/bin/sh
    2. port=3306
    3. cmdPath="/usr/local/mysql/bin"
    4. myPath="/storage/mysql/$port"
    5. softPath="/usr/local/mysql"
    6. socketfile="/tmp/mysql$port.sock"
    7. my_user="root"
    8. my_pass="123456"
    9. start(){
    10. if [ ! -e "$socketfile" ];then
    11. printf "Mysqldstarting......\n"
    12. $cmdPath/mysqld --defaults-file=/etc/my$port.cnf --user=mysql &>/dev/null &
    13. sleep 2
    14. else
    15. printf "Mysqld alreadyrunning\n" && exit 1
    16. fi
    17. }
    18. stop(){
    19. if [ -e "$socketfile" ];then
    20. printf "Mysqldstoping......\n"
    21. $cmdPath/mysqladmin -u"$my_user" -p"$my_pass" \
    22. -S "$socketfile" shutdown &>/dev/null
    23. [ $? -ne 0 ] && echo"error username or password!!!" && exit 1
    24. sleep 3
    25. else
    26. printf "Mysqld alreadyclosed\n" && exit 1
    27. fi
    28. }
    29. restart(){
    30. stop
    31. start
    32. }
    33. case "$1" in
    34. start)
    35. start
    36. ;;
    37. stop)
    38. stop
    39. ;;
    40. restart)
    41. restart
    42. ;;
    43. status)
    44. status mysqld
    45. ;;
    46. *)
    47. echo "Usage: $0{start|stop|restart|status}"
    48. exit 1
    49. esac