Mariadb多实例启动脚本

  1. #!/bin/bash
  2. port=3306
  3. mysql_user="root"
  4. mysql_pwd="centos"
  5. cmd_path="/app/mysql/bin"
  6. mysql_basedir="/mysqldb"
  7. mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"
  8. function_start_mysql()
  9. {
  10. if [ ! -e "$mysql_sock" ];then
  11. printf "Starting MySQL...\n"
  12. ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
  13. else
  14. printf "MySQL is running...\n"
  15. exit
  16. fi
  17. }
  18. function_stop_mysql()
  19. {
  20. if [ ! -e "$mysql_sock" ];then
  21. printf "MySQL is stopped...\n"
  22. exit
  23. else
  24. printf "Stoping MySQL...\n"
  25. ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
  26. fi
  27. }
  28. function_restart_mysql()
  29. {
  30. printf "Restarting MySQL...\n"
  31. function_stop_mysql
  32. sleep 2
  33. function_start_mysql
  34. }
  35. case $1 in
  36. start)
  37. function_start_mysql
  38. ;;
  39. stop)
  40. function_stop_mysql
  41. ;;
  42. restart)
  43. function_restart_mysql
  44. ;;
  45. *)
  46. printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
  47. esac
posted @ 2018-02-28 13:58  莫孟林  阅读(188)  评论(0编辑  收藏  举报