-
-
Save kappaj/aa61b7e5df7ec02a21d89984b287eb4c 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