docker-images/pluie/alpine-mysql/dbcreate.sh
a-sansara e185c732dc mysql : add various scripts
all   : fix terminal ENV context and add doc nav
2016-08-03 01:38:18 +02:00

43 lines
854 B
Bash
Executable File

#!/bin/bash
# pluie/docker-images - a-Sansara (https://github.com/a-sansara)
. /scripts/dbcommon.sh
dbname=${1:-''}
dbuser=${2:-''}
shname=$(basename $0)
echoTitle
function usage(){
echo -e "\n ${Cusa}usage :${Coff}\n ${Ctext}$shname \t${Copt}DBNAME ${Cspe}[${Copt}USER${Cspe}]${Coff}"
}
mktfile
if [ ! -z "$dbname" ]; then
cat <<EOF > "$tfile"
CREATE DATABASE IF NOT EXISTS \`$dbname\` CHARACTER SET utf8 COLLATE utf8_general_ci;
EOF
if [ ! -z "$dbuser" ]; then
cat <<EOF >> "$tfile"
GRANT ALL ON \`$dbname\`.* to '$dbuser'@'localhost';
GRANT ALL ON \`$dbname\`.* to '$dbuser'@'%';
EOF
fi
echo "FLUSH PRIVILEGES;" >> "$tfile"
echo
cat "$tfile" | sed "s/^/ /";
echo
mysql -uroot < "$tfile"
if [ $? -eq 0 ]; then
echo -e "\n done"
fi
echo
rm -f "$tfile"
else
errEmptyDb
fi