Contents

[bash] Mysql usr/db/psw multiple creation

Script for creation of multiple databases/users on mysql

#!/bin/bash
file="users_all"
while IFS=, read -r user db pswd host
do

	mysql -e "CREATE USER '$user'@'$host';"
	mysql -e "CREATE DATABASE $db;"
	mysql -e "GRANT ALL PRIVILEGES ON $db.* TO '$user'@'$host' IDENTIFIED BY '$pswd';"

done <"$file"

file with parameters (users_all)

	user01,db01,psw01,host01
	user02,db02,psw02,host02