Last active
April 28, 2018 00:38
-
-
Save hosquiat/d021c70b75419cfb3f0229deb1ea99e6 to your computer and use it in GitHub Desktop.
Create and provision a mysql script quickly... Script expects a database name user and password.
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 USAGE ON *.* TO $2@localhost IDENTIFIED BY '$3';" | |
Q3="GRANT ALL PRIVILEGES ON $1.* TO $2@localhost;" | |
Q4="FLUSH PRIVILEGES;" | |
SQL="${Q1}${Q2}${Q3}${Q4}" | |
if [ $# -ne $EXPECTED_ARGS ] | |
then | |
echo "Usage: $0 dbname dbuser dbpass" | |
exit $E_BADARGS | |
fi | |
$MYSQL -uroot -p -e "$SQL" | |
################################################################################################################################# | |
# Sometimes, you may wish to install programs into other locations on your computer, but be able to execute them easily without | |
# specifying their exact location. You can do this easily by adding a directory to your $PATH. To see what's in your $PATH right | |
# now, type in: | |
# PATH=`$PATH` | |
# You'll probably see the directories mentioned above, as well as perhaps some others, and they are all separated by colons. Now | |
# let's add another directory to the list. | |
# Let's say you wrote a little shell script called hello.sh and have it located in a directory called /place/with/the/file. This | |
# script provides some useful function to all of the files in your current directory, that you'd like to be able to execute no matter | |
# what directory you're in. | |
# Simply add /place/with/the/file to the $PATH variable with the following command: | |
# export PATH=$PATH:/place/with/the/file | |
# You should now be able to execute the script anywhere on your system by just typing in its name, without having to include the full | |
# path as you type it. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment