Skip to content

Instantly share code, notes, and snippets.

@michellescripts
Created November 4, 2020 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michellescripts/617814ac41329487da03fb6d8326989e to your computer and use it in GitHub Desktop.
Save michellescripts/617814ac41329487da03fb6d8326989e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
database=${database:-some_database}
test_database=${database:-some_test_database}
user=${user:-$database}
password=${password:-password}
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
v="${1/--/}"
declare $v="$2"
# echo $1 $2 // Optional to see the parameter:value result
fi
shift
done
cat > /tmp/create_db.sql <<EOL
CREATE USER '${user}'@'%' IDENTIFIED BY '${password}';
CREATE DATABASE ${database};
GRANT ALL PRIVILEGES ON ${database} . * to '${user}'@'%';
CREATE DATABASE ${test_database};
GRANT ALL PRIVILEGES ON ${test_database} . * to '${user}'@'%';
EOL
docker create \
--name a-mariadb \
--rm \
-p 3306:3306 \
--env MYSQL_ROOT_PASSWORD=password \
mariadb:latest
docker cp /tmp/create_db.sql a-mariadb:/docker-entrypoint-initdb.d/
echo ""
echo "*************** ATTENTION *****************"
echo ""
echo "Process must be stopped via ctrl-\ instead of ctrl-c"
echo ""
echo "*************** /ATTENTION *****************"
echo ""
sleep 3
docker start a-mariadb -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment