ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 创建管理MySQL数据库的shell脚本

创建管理MySQL数据库的shell脚本

原创 Linux操作系统 作者:markzy5201190 时间:2012-12-26 21:29:22 0 删除 编辑
//创建管理MySQL数据库的shell脚本;
#!/bin/bash

mysql_port=3306
mysql_username="admin"
mysql_password="123456"

//启动MySQL
function_start_mysql(){
printf "Starting MySQL...\n"
/usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf >2&1 > /dev/null &
}

//停止MySQL
function_stop_mysql(){
printf "Stop MySQL...\n" OR  echo -e "Stop MySQL..."
/usr/local/webserver/mysql/bin/mysqladmin -h localhost -P${mysql_port} -u${mysql_username} -p${mysql_password} shutdown 
OR
    /usr/local/webserver/mysql/bin/mysqladmin -h localhost -P${mysql_port} -u${mysql_username} -p${mysql_password} -S /path/mysql.sock shutdown
}
//重启MySQL
function_restart_mysql(){
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}

//非正常关闭MySQL
function_kill_mysql(){
kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{print $2}')
kill -9 $(ps -ef | grep 'libexec/mysqld | grep ${mysql_port}' | awk '{print $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:/usr/mysql {start|stop|restart|kill}\n"
fi

chmod +x /usr/local/shell/mysqld

/usr/local/shell/mysqld start
/usr/local/shell/mysqld stop
/usr/local/shell/mysqld kill
.....

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26855487/viewspace-751687/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-04-05

  • 博文量
    82
  • 访问量
    472458