mysql日常这点事儿(5)mysql服务启动停止kill的..
时间:2010-03-09 来源:pkman110
张宴写的mysql起停kill脚本可以借鉴
- #!/bin/sh
- mysql_port=3306
- mysql_username="admin"
- mysql_password="12345678"
- function_start_mysql()
- {
- printf "Starting MySQL...\n"
- /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
- }
- function_stop_mysql()
- {
- printf "Stoping MySQL...\n"
- /usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
- }
- function_restart_mysql()
- {
- printf "Restarting MySQL...\n"
- function_stop_mysql
- sleep 5
- function_start_mysql
- }
- function_kill_mysql()
- {
- kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
- kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
- }
- 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: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"
- fi
相关阅读 更多 +