-
-
Save netpedro-com/4e48aecd2284d8dba0f6355cf2ba548f to your computer and use it in GitHub Desktop.
Initialising multiple databases inside a Docker MySQL image
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 | |
# ** usage ** | |
# initialize a MYSQL_DATABASES env variable in the container with space separated db names | |
# e.g. MYSQL_DATABASES="foo bar" | |
# assumes that MYSQL_ROOT_PASSWORD and MYSQL_USER are set | |
function create_database() { | |
local DATABASE=$1 | |
echo "Creating database '${DATABASE}'" | |
mysql -uroot -p${MYSQL_ROOT_PASSWORD} <<-EOSQL | |
CREATE DATABASE \`${DATABASE}\`; | |
GRANT ALL ON \`${DATABASE}\`.* TO '${MYSQL_USER}'@'%'; | |
EOSQL | |
} | |
for DATABASE in ${MYSQL_DATABASES[*]}; do | |
create_database $DATABASE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment