Created
September 13, 2018 17:11
-
-
Save cygmris/507df0dfec1804a4bd2ecf7447d7c3ce to your computer and use it in GitHub Desktop.
mysql_batch_create_user.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "Input the mysql password of root user" | |
| read -s MYSQL_PASSWORD | |
| echo "Input the mysql database name we are gona create" | |
| read DATABASE_NAME | |
| echo "How mant database do you what to create: " | |
| read DATABASE_NUM | |
| mysql -uroot -p$MYSQL_PASSWORD -e "CREATE USER '$DATABASE_NAME'@'%' IDENTIFIED BY '$DATABASE_NAME';" | |
| for ((i=1;i<=$DATABASE_NUM;i++)) | |
| do | |
| mysql -uroot -p$MYSQL_PASSWORD -e "create database ${DATABASE_NAME}${i};grant all privileges on ${DATABASE_NAME}${i}.* to ${DATABASE_NAME}@'%'" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment