Created
February 26, 2016 14:13
-
-
Save matteocaberlotto/702a9c7fc3043d6c636e to your computer and use it in GitHub Desktop.
bash script to create user and database
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 | |
if [ "$1" == "" ]; then | |
echo "Error: database required: use create-database <db_name> <username> <password>" | |
exit 1 | |
fi | |
if [ "$2" == "" ]; then | |
echo "Error: username required: use create-database <db_name> <username> <password>" | |
exit 1 | |
fi | |
if [ "$3" == "" ]; then | |
echo "Error: password required: use create-database <db_name> <username> <password>" | |
exit 1 | |
fi | |
mysql -u root -p -e "CREATE DATABASE $1 CHARACTER SET utf8 COLLATE utf8_unicode_ci" | |
mysql -u root -p -e "CREATE USER '$2'@'localhost' IDENTIFIED BY '$3'" | |
mysql -u root -p -e "GRANT ALL PRIVILEGES ON $1.* TO '$2'@'localhost'" | |
mysql -u root -p -e "FLUSH PRIVILEGES" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment