Skip to content

Instantly share code, notes, and snippets.

@BetaStacks
Forked from askz/create-mysql.bash
Last active July 27, 2017 13:57
Show Gist options
  • Save BetaStacks/86f8aae4de8ac7b087e7683e65ce25fc to your computer and use it in GitHub Desktop.
Save BetaStacks/86f8aae4de8ac7b087e7683e65ce25fc to your computer and use it in GitHub Desktop.
Simple bash script to create mysql db, user with generated password
#!/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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment