1、说明
查看mysql数据库中所有非root用户的权限
在迁移数据库时会用到
2、运行示例
先提示输入mysql密码,输入密码后,检查密码的正确性,如果正确则输出mysql用户权限
运行过程中会产生两个文件user.lst和user.grants
user.lst 记录数据库中所有用户
user.grants 记录用户权限
- Input mysql password :
-
======================================================================================
-
--------------------------------------------------------------------------------------
-
Grants for test@192.168.1%
-
GRANT USAGE ON *.* TO 'test'@'192.168.1%' IDENTIFIED BY PASSWORD 'password'
-
GRANT ALL PRIVILEGES ON `test%`.* TO 'test'@'192.168.1%' WITH GRANT OPTION
-
--------------------------------------------------------------------------------------
-
======================================================================================
3、代码
- #!/bin/bash
-
#
-
#
-
#2012/01/10 anmile
-
-
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
-
HOME=/user/local/games
-
-
Show_Grants(){
-
mysql -uroot -p"$DB_PWD" -e "select user,host from mysql.user;">user.lst
-
sed -i '1d' user.lst
-
echo "======================================================================================">user.grants
-
echo "--------------------------------------------------------------------------------------">>user.grants
-
for i in `awk '$2!=null && $1!="root" {printf "\047%s\047@\047%s\047\n",$1,$2}' user.lst `
-
do
-
mysql -uroot -p"$DB_PWD" -e "show grants for $i">>user.grants
-
echo "--------------------------------------------------------------------------------------">>user.grants
-
done
-
echo "======================================================================================">>user.grants
-
less user.grants
-
}
-
-
CHECK_MYSQL_PWD(){
-
unset PWD_CHECK DB_PWD
-
echo -e "\033[1;40;36m"
-
echo -ne "Input mysql password : "
-
echo -ne "\033[0m"
-
read -s DB_PWD
-
while :
-
do
-
if [ -z "$DB_PWD" ] ;then
-
echo
-
echo -ne "\033[1;40;31m"
-
echo -ne "the password is null,please reinput:"
-
echo -ne "\033[0m"
-
read -s DB_PWD
-
continue
-
fi
-
PWD_CHECK=$(mysqladmin -uroot -p"$DB_PWD" ping 2>/dev/null|grep alive)
-
if [ -z "$PWD_CHECK" ];then
-
echo
-
echo -ne "\033[1;40;31m"
-
echo -ne "the password"
-
echo -ne "\033[1;40;35m"
-
echo -ne "($DB_PWD)\033[1;40;31m is wrong,please reinput:"
-
echo -ne "\033[1;40;31m "
-
echo -ne "is wrong,please reinput:"
-
echo -ne "\033[0m"
-
read -s DB_PWD
-
continue
-
elif [ "$PWD_CHECK" = "mysqld is alive" ];then
-
Show_Grants
-
break
-
fi
-
done
-
}
-
-
CHECK_MYSQL_PWD
阅读(2646) | 评论(0) | 转发(0) |