#!/bin/bash
# The script will fail at the first error encountered
set -e
echo "Type the name for your database, followed by [ENTER]:"
read DB
echo "Type the username for your database, followed by [ENTER]:"
read USR
echo "Type the password for your new user, followed by [ENTER]:"
read PASS
mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE $DB;
CREATE USER '$USR'@'localhost' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON $DB.* TO '$USR'@'localhost';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
echo "MySQL user created."
echo "Database: $DB"
echo "Username: $USR"
echo "Password: $PASS"