Created
May 21, 2016 10:00
-
-
Save Ulv/aecee361723c5c412ca29bc4cf170aed to your computer and use it in GitHub Desktop.
Create mysql database and user
This file contains hidden or 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 | |
EXPECTED_ARGS=3 | |
E_BADARGS=65 | |
MYSQL=`which mysql` | |
Q1="CREATE DATABASE IF NOT EXISTS $1;" | |
Q2="GRANT ALL ON *.* TO '$2'@'localhost' IDENTIFIED BY '$3';" | |
Q3="FLUSH PRIVILEGES;" | |
SQL="${Q1}${Q2}${Q3}" | |
if [ $# -ne $EXPECTED_ARGS ] | |
then | |
echo "Usage: $0 dbname dbuser dbpass" | |
exit $E_BADARGS | |
fi | |
echo "Enter root password when prompted" | |
$MYSQL -uroot -p -e "$SQL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment