20 lines
370 B
Bash
20 lines
370 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
EXPECTED_ARGS=3
|
||
|
E_BADARGS=65
|
||
|
MYSQL=`which mysql`
|
||
|
|
||
|
Q1="CREATE DATABASE $1;"
|
||
|
Q2="CREATE USER $2;"
|
||
|
Q3="GRANT ALL ON $1.* TO '$2'@'localhost';"
|
||
|
Q4="SET password for '$2'@'localhost' = password('$3')"
|
||
|
SQL="${Q1}${Q2}${Q3}${Q4}"
|
||
|
|
||
|
if [ $# -ne $EXPECTED_ARGS ]
|
||
|
then
|
||
|
echo "Usage: $0 dbname dbuser dbpass"
|
||
|
exit $E_BADARGS
|
||
|
fi
|
||
|
|
||
|
$MYSQL -uroot -pzekzek -e "$SQL"
|