#!/bin/bash

#ARG 1 - Username
if [ $# = 1 ];
then
{
randpass()
{
[ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
cat /dev/urandom | tr -cd "$CHAR" | head -c 15
echo
}

pass=$(randpass 15 0)
Q1="CREATE DATABASE IF NOT EXISTS $1_db;"
Q2="GRANT ALL ON $1_db.* TO $1_user@localhost BY '$pass';"
Q3="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}"
$MYSQL -uroot -pPASSWORD -e "$SQL"
echo "Credentials"
echo $1_db
echo $1_user
echo $DBSERVER
echo $pass2
}
else
{
echo "usage: $0 "
}
fi