Skip to content

Instantly share code, notes, and snippets.

@cygmris
Created September 13, 2018 17:11
Show Gist options
  • Select an option

  • Save cygmris/507df0dfec1804a4bd2ecf7447d7c3ce to your computer and use it in GitHub Desktop.

Select an option

Save cygmris/507df0dfec1804a4bd2ecf7447d7c3ce to your computer and use it in GitHub Desktop.
mysql_batch_create_user.sh
#!/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