六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 62|回复: 0

重置mysql数据库shell脚本

[复制链接]

升级  53.33%

32

主题

32

主题

32

主题

秀才

Rank: 2

积分
130
 楼主| 发表于 2013-2-4 13:46:59 | 显示全部楼层 |阅读模式
#!/bin/bashuser=pwd=function help_info(){    echo "Tool to reset mysql server"    echo "Usage:"    echo "$0 <user> <pwd>"}if [ $# -eq 2 ];then    user=$1    pwd=$2elif [ $# -ne 2 ];then    help_info    exit 1fisrc=/usr/local/mysql/datacd $srcmv mysql mysql_bak && mv performance_schema performance_schema_bak &&  mv test test_bak >/dev/null 2>&1rm -rf `ls | grep [^_bak]$`mv mysql_bak mysql;mv performance_schema_bak performance_schema; mv test_bak testservice mysql restartmysql_status=`service mysql status | grep  "MySQL running" | awk -F " " '{print $1 $2}'`#echo $mysql_statusif [ "$mysql_status" == "MySQLrunning" ];thenecho "MYSQL server is running"else   echo "Begin to start mysql server..."kill -9 `ps -ef | grep "/usr/local/mysql/bin" | grep -v grep | awk -F " " '{print  $2}'`&& service mysql  startfifunction clearData(){echo "Begin to reset  mysql server" mysql -h 127.0.0.1 -u$user -p$pwd << EOFuse mysql;delete from user where user not in('root','mysql');delete from user where user='mysql' and host not in ('localhost','linux','127.0.0.1','::1','%');stop slave ;reset master;EOFif [ $? -eq 0 ];thenecho "Reset mysql server sucessfully..." else echo "Reset mysql fail..."fi}clearData  
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表