mysql 启动、重启、kill脚本

vi mysql

#!/bin/sh        
mysql_port=3306        
mysql_username="root"    
mysql_password=""    
    
start_mysql()        
{        
        printf "Starting MySQL...\n"    
        /bin/sh /data1/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf 2>&1 > /dev/null &        
}        
    
stop_mysql()        
{        
        printf "Stoping MySQL...\n"    
        /data1/mysql/bin/mysqladmin -u ${mysql_username}    -S /tmp/mysql.sock shutdown        
}        
    
restart_mysql()        
{        
        printf "Restarting MySQL...\n"    
        stop_mysql        
        sleep 5        
        start_mysql        
}        
    
kill_mysql()        
{        
        kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep 'my.cnf' | awk '{print $2}')        
        kill -9 $(ps -ef | grep 'libexec/mysqld'    | grep 'my.cnf' | awk '{print $2}')        
}        
    
if [ "$1" = "start" ]; then        
        start_mysql        
elif [ "$1" = "stop" ]; then        
        stop_mysql        
elif [ "$1" = "restart" ]; then        
        restart_mysql        
elif [ "$1" = "kill" ]; then        
        kill_mysql        
else    
        printf "Usage: /app/mysql {start|stop|restart|kill}\n"    
fi