User and password generation management in mysql bitsCN.com
User and password generation management in mysql
Application launch involves user name and password management. as the launch application increases, user name and password management settings become a problem. We also need to grant permissions to users, so we want to write a script for management and see a script written by our colleagues to meet our needs. The idea is to replace letters with numbers, and the account is set based on the database name. The script is as follows:
#!/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';"
Usage script followed by db name
[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';
After the preceding SQL statement is generated, a write account and a read account are generated, and commands are executed on the corresponding host.
BitsCN.com