Created
September 14, 2014 02:02
-
-
Save tg90nor/c61c977e6903ef2b9cdc to your computer and use it in GitHub Desktop.
createdb
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 | |
EXPECTED_ARGS=1 | |
E_BADARGS=65 | |
MYSQL=`which mysql` | |
PASS=`openssl rand -base64 16` | |
Q1="CREATE DATABASE IF NOT EXISTS $1;" | |
Q2="GRANT ALL ON $1.* TO '$1'@'localhost' IDENTIFIED BY '$PASS';" | |
Q3="FLUSH PRIVILEGES;" | |
SQL="${Q1}${Q2}${Q3}" | |
if [ $# -ne $EXPECTED_ARGS ] | |
then | |
echo "Usage: $0 dbname" | |
exit $E_BADARGS | |
fi | |
echo "$SQL" | |
$MYSQL -u root -e "$SQL" | |
echo Generated password: $PASS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment