Multi-instance MySQL bulk add users and passwords and authorize

Source: Internet
Author: User

Os:cent OS 6.3

db:5.5.14

If there are 100 MySQL DB instances on a server, you need to add a user name, password and authorization application IP to several databases of different ports, authorization is not a problem, anyway tired is not me, wow ka ka.


Create add_user.sh

#/bin/bash
#add user to MySQL DB


Passpwd= "Yoon"


Cat User.txt | While read user
Do
Port= ' echo $user |awk ' {print $} '
Username= ' echo $user |awk ' {print $} '
Pwd= ' echo $user |awk ' {print $} '
Db= ' echo $user |awk ' {print $4} '
# echo ' port= ' $port ', username= ' $username ';p wd= ' $pwd ';d b= ' $db


/export/servers/mysql/bin/mysql-s/export/data/mysql/tmp/mysql$port.sock-uroot-p$passpwd <<EOF


Use MySQL;


GRANT select,insert,update,delete on $db. * to ' $username ' @ ' 192.17.12.2 ' identified by ' $pwd ';
GRANT select,insert,update,delete on $db. * to ' $username ' @ ' 192.17.12.3 ' identified by ' $pwd ';
GRANT select,insert,update,delete on $db. * to ' $username ' @ ' 192.17.12.4 ' identified by ' $pwd ';


Flush privileges;


Eof



Done



Create User.txt

YOON_RW Wy811jnjtzcjjfzo. Ui_8q8i8k09kx Yoon
YOON_RW Wy811jnjtzcjjfzo. Ui_8q8i8k10kx Yoon
YOON_RW Wy811jnjtzcjjfzo. Ui_8q8i8k11kx Yoon
YOON_RW Wy811jnjtzcjjfzo. Ui_8q8i8k12kx Yoon
YOON_RW Wy811jnjtzcjjfzo. Ui_8q8i8k13kx Yoon
2018 Yoon_rw Wy811jnjtzcjjfzo. Ui_8q8i8k14kx Yoon
2020 YOON_RW Wy811jnjtzcjjfzo. Ui_8q8i8k15kx Yoon


[Email protected] ~]# sh add_user.sh

Multi-instance MySQL bulk add users and passwords and authorize

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.