The new company because of some business reasons have good hundreds of group win machine installed MySQL license login More trouble, simply write a shell automatic authorization script, save reuse.
#!/bin/bash#author [Email protected]function Helpfunc () {ECHO-E] \033[36m please check your parameters,-D For DB name,-M main library IP,-I for Authorized IP address options:-D need to authorize the DB n Ame-m Execute on this ip-i Authorized ip-t Authorization Type 1 is the Progr Am account, 2 read-only account, 3 Administrator account; Can specify multiple to ', ' separation eg:mysqlha_winreplication.sh-d-m-i-T Generate 3 Acco Unts:1st:program link account. Permissions:select, INSERT, UPDATE, DELETE, EXECUTE, no DROP, CREATE; 2nd:read-only account. Permissions:select 3rd:administrator account. Permissions:all \033[0m "}########################################### #type =2if [$#-lt 1]; Then Helpfunc exit 1else while Getopts "M:d:i:t:" Option does case $Option in D) db= $OPTARG;; M) master_ip= $OPTARG;; I) grant_ip= $OPTARG;; T) type= $OPTARG;; *) Helpfunc; Exit 1;;; Esac donefitype=$ (Echo $type |tr ', ') function getpwd () {status=$1if [$status-eq 0];then a= ' head-c 500 /dev/urandom | TR-DC A-Z |head-c 1 ' b= ' head-c 500/dev/urandom | TR-DC [: alnum:]| Head-c 6 ' c= ' echo $RANDOM $random|cut-c 2 ' echo $A $b$celse a= ' head-c 500/dev/urandom | TR-DC A-Z |head-c 1 ' b= ' head-c 500/dev/urandom | TR-DC [: alnum:]| Head-c ' c= ' echo $RANDOM $random|cut-c 2 ' echo $A $B$CFI} # echo-e "\033[42;37m \033[0m" function Getprogram () {pro_pwd=$ (getpwd 0) #ssh [email protected]${master_ip} "Cd/cygdrive/d/data/mysqld_master && cmd/c sql.bat \ "$sql \" # #读写pro_sql = "GRANT select,insert,update,delete,execute on ${db}.* to ${db}@ '" LocalHost "' identified by '" $pRo_pwd "'; "Pro_sql1=" GRANT Select,insert,update,delete,execute on ${db}.* to ${db}@ ' "${grant_ip}" ' Identified by ' "$pro _pwd"; ' For SQL in ' $pro _sql "" $pro _sql1 "do if SSH [email protected]${master_ip}" Cd/cygdrive/d/data/mysqld_master && cmd/c sql.bat \ "$sql \" "; Then:else echo-e" \033[31m to grant Authoriz ATION{IP:${MASTER_IP} permissions: Read/write} faild \033[0m "Fidoneecho-e" \033[32m to grant AUTHORIZATION{IP:${MASTER_IP} permissions: Read/write } sucess \033[0m "Echo-e" \033[32m read-Write account: ${db} \033[0m "Echo-e" \ 033[32m read-write password: ${pro_pwd} \033[0m "}function Getselect () {select_pwd=$ (GETPW d 1) # #只读select_sql = "GRANT SELECT on ${db}.*-${db}[email protected] '" localhost "' identified by '" $select _pwd "';" select_sql1= "GRANT SELECT on ${db}.* to ${db}[email protected] '" ${grant_ip} "' Identified by '" $select _pwd "';" For SQL in "$select _sql" "$selECT_SQL1 "Do if SSH [email protected]${master_ip}" Cd/cygdrive/d/data/mysqld_master && cmd/c Sql.bat \ "$sql \" "; Then:else echo-e" \033[31m to grant AUTHORIZATION{IP:${MASTER_IP} permissions: Read Only} faild \033[0m "fi else Echo-e" \033[31m to grant AUTHORIZATION{IP:${MASTER_IP} permissions: Read Only} Faild \033[0m "FIDONEECHO-E" \033[32m to grant AUTHORIZATION{IP:${MASTER_IP} permissions: Read only} sucess \033[0m "Echo-e" \033[32M read-only account: ${db}_r \033[0m "ECHO-E" \033[32m read-only password: ${select_pwd} \033[0m "}function getadmin () {admin_pwd=$ (getpwd 2) #管理员admin_sql =" Grant Select,insert, Update,delete,create,drop,alter,index,lock tables, create temporary tables on ${db}.* to ${db}[email protected] ' " LocalHost "' identified by '" $admin _pwd "';" Admin_sql= "Grant Select,insert,update,delete,create,drop,alter,index,lock tables, create temporary tables On ${db}.* to ${db}[email protected] ' "127.0.0.1" ' Identified by ' "$admin _pwd" '; " For SQL in "$admin _sql" "$admin _sql1" do if SSH [email protected]${master_ip} "Cd/cygdrive/d/data/mysqld_mast Er && cmd/c sql.bat \ "$sql \" "Then:else echo-e" \033[31m to grant Autho RIZATION{IP:${MASTER_IP} permissions: admin} faild \033[0m "Fidoneecho-e" \033[32m to grant Authorization{ip:localhost permissions: Tube Manager} sucess \033[0m "ECHO-E" \033[32m Administrator account: ${db}_admin \033[0m "Echo-e" \033[32M Administrator password: ${admin_pwd} \033[0m "}function main () {for Stu in $typedo If [$stu-eq 1];then getprogram elif [$stu-eq 2];then getselect elif [ $stu-eq 3];then getadmin Else echo-e "\033[31m please check if your type Paramet ER is in range \033[0m "Fidone}main
Call Win Sql.bat
@echo Offset Allparam=%1d:\data\mysqld_master\bin\mysql.exe-uroot-e%allparam%
or +port
@echo offset Allparam=%2set Port=%1echo%1echo%2d:\data\mysqld_slave\bin\mysql.exe-uroot-p%port%-E%allparam%
eg:mysqlha_winreplication.sh-d -m-i-T
Shell +cygwinterminal+winmysql Pass Parameter authorization