MySQL
========================================================================
#!/bin/bash
mysql_port=3306
mysql_username="test"
mysql_password=""
mysql_conf="/etc/my.cnf"
mysql_sock="/var/lib/mysql/mysql.sock"
function_start_mysql(){
printf "Starting MySQL ...\n"
/bin/sh /usr/bin/mysqld_safe --defaults-file=${mysql_conf} 2>&1 > /dev/null &
}
function_stop_mysql(){
printf "Stopping MySQL ...\n"
/usr/bin/mysqladmin --port=${mysql_port} --user=${mysql_username} --password=${mysql_password} --socket=${mysql_sock} shutdown
}
function_restart_mysql(){
printf "Restarting MySQL ...\n"
function_stop_mysql
sleep 3
function_start_mysql
}
function_kill_mysql(){
ps -ef | grep "mysqld_safe" | grep -v grep | awk '{print "kill -9 " $2}' | /bin/sh
ps -ef | grep "mysqld" | grep -v grep | awk '{print "kill -9 " $2}' | /bin/sh
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: mysql {start|stop|restart|kill}\n"
fi
