-
-
Save BetaStacks/86f8aae4de8ac7b087e7683e65ce25fc to your computer and use it in GitHub Desktop.
Simple bash script to create mysql db, user with generated password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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