Created
July 2, 2018 06:46
-
-
Save tksugimoto/2ba7f56fad7c3fadb91c9b5ebf9d0518 to your computer and use it in GitHub Desktop.
Docker MySQLの初期化処理:サブディレクトリの *.sql なども対象にする
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
#!/bin/bash | |
# https://github.com/docker-library/mariadb/blob/1e7c5c9bb2bfde0453fb52175343a360ed346104/10.3/docker-entrypoint.sh#L169-L177 | |
# サブディレクトリまで見る | |
# -print0: 区切り文字を \0 に変更(名前中のスペース対策) | |
find /docker-entrypoint-initdb.d/*/* -type f -print0 | while IFS= read -r -d '' f; do | |
case "$f" in | |
*.sh) echo "$0: running $f"; . "$f" ;; | |
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; | |
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;; | |
*) echo "$0: ignoring $f" ;; | |
esac | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment