Skip to content

Instantly share code, notes, and snippets.

@9ete
Created May 8, 2015 22:12
Show Gist options
  • Save 9ete/4f06b2786fc8c93bd61c to your computer and use it in GitHub Desktop.
Save 9ete/4f06b2786fc8c93bd61c to your computer and use it in GitHub Desktop.
Create database quickly
#!/bin/bash
BTICK='`'
EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`
Q1="CREATE DATABASE IF NOT EXISTS ${BTICK}$1${BTICK};"
Q2="GRANT ALL ON ${BTICK}$1${BTICK}.* 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
$MYSQL -uroot -p -e "$SQL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment