Skip to content

Instantly share code, notes, and snippets.

@tksugimoto
Created July 2, 2018 06:46
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 tksugimoto/2ba7f56fad7c3fadb91c9b5ebf9d0518 to your computer and use it in GitHub Desktop.
Save tksugimoto/2ba7f56fad7c3fadb91c9b5ebf9d0518 to your computer and use it in GitHub Desktop.
Docker MySQLの初期化処理:サブディレクトリの *.sql なども対象にする
#!/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