- #!/bin/bash
- port=3306
- mysql_user="root"
- mysql_pwd="centos"
- cmd_path="/app/mysql/bin"
- mysql_basedir="/mysqldb"
- mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"
- function_start_mysql()
- {
- if [ ! -e "$mysql_sock" ];then
- printf "Starting MySQL... "
- ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
- else
- printf "MySQL is running... "
- exit
- fi
- }
- function_stop_mysql()
- {
- if [ ! -e "$mysql_sock" ];then
- printf "MySQL is stopped... "
- exit
- else
- printf "Stoping MySQL... "
- ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
- fi
- }
- function_restart_mysql()
- {
- printf "Restarting MySQL... "
- function_stop_mysql
- sleep 2
- function_start_mysql
- }
- case $1 in
- start)
- function_start_mysql
- ;;
- stop)
- function_stop_mysql
- ;;
- restart)
- function_restart_mysql
- ;;
- *)
- printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart} "
- esac