Created
November 4, 2020 20:29
-
-
Save michellescripts/617814ac41329487da03fb6d8326989e to your computer and use it in GitHub Desktop.
This file contains 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
#!/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