Home  >  Article  >  Database  >  mysql下用户和密码生成管理_MySQL

mysql下用户和密码生成管理_MySQL

WBOY
WBOYOriginal
2016-06-01 13:32:13890browse

bitsCN.com

mysql下用户和密码生成管理

 

应用上线,涉及到用户名和密码管理,随着上线应用的增加,用户名和密码的管理设置成为一个问题。还要对用户赋权,于是想着写一个脚本来管理,看到同事写的一个脚本,满足需求。思路大致是字母替换为数字,账号根据库名设置。脚本如下:

 

#!/bin/shpasswd1=$1_sirdbuser=`echo $passwd1|awk '{print tolower($0)}'`dbpassword=`echo $passwd1| awk '{print  tolower($0)}' |sed '//n/!G;s//(./)/(.*/n/)/&/2/1/;//D;s/.//'|awk '{    toupper($0)    gsub(/_/,"",$0)    while($0~/a/)    {        gsub(/a/,"4",$0)    }    while($0~/e/)    {        gsub(/e/,"3",$0)    }           while($0~/i/)    {        gsub(/i/,"1",$0)    }           while($0~/o/)    {        gsub(/o/,"0",$0)    }           while($0~/v/)    {        gsub(/v/,"7",$0)    }    print  tolower($0)}'`echo "grant select,update,delete,insert on $1.* to $dbuser@'%' identified by '$dbpassword';"echo "grant select on $1.* to reader@'%' identified by 'n0p4ssw0rd';"

 

 

使用方式  脚本后面跟db名字

[root@dbxxxxx]# ./password.sh userdbgrant select,update,delete,insert on userdb.* to userdb_sir@'%' identified by 'r1sbdr3su';grant select on userdb.* to reader@'%' identified by 'n0p4ssw0rd';

 

 

执行完产生上面的sql语句,一个写账号,一个读账号,然后在相应主机上执行命令。

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn