Asked By
toles hitz
10 points
N/A
Posted on - 02/13/2013
Hello experts,
I am preparing a sever and database for my office.
Firstly I have to design for 50 users.
I am newbie and don’t know how to do this.
I have searched the term “managing users in MySQL 50” and found a variety of results.
I am looking for script with each explanation.
So I can make changes at any stage whenever I required.
Have you tried to Managing users in mysql 50
Hi Toles,
First store all the 50 usernames and password s in csv file.
e.g mike,mike123
rose,rose123
zen,zen1234
Then write a bash script to read the csv file line by line and then use the create user command to create mysql users.
#!/bin/bash
INPUT=username.cvs
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read username pwd
do
cmd1="CREATE user’$username’@’localhost’ identified by password ‘$pwd’;"
cmd2="GRANT ALL PRIVILEGES ON *.* TO '$username'@'localhost' ;“
cmd3="FLUSH PRIVILEGES;"
SQL="${cmd1}${cmd2}${cmd3}"
$MYSQL -uroot -p -e "$SQL"
done
IFS=$OLDIFS
If you want to add or delete users you just need to update the csv file.
Hope this will help you. Best of luck