Skip to content

Instantly share code, notes, and snippets.

@enzinier
Created June 26, 2017 23:06
Show Gist options
  • Save enzinier/f11b924cb57316aa7900c5a986a6e69c to your computer and use it in GitHub Desktop.
Save enzinier/f11b924cb57316aa7900c5a986a6e69c to your computer and use it in GitHub Desktop.
Job for initializing database when database is connected.
#!/bin/bash
OUTPUT=""
until [[ ! "$OUTPUT" == "" ]]; do
echo "Not Connect!"
OUTPUT=$(mysql -h127.0.0.1 -uroot -p$MYSQL_ROOT_PASSWORD -e "SHOW DATABASES;" 2>/dev/null)
sleep 1
done
echo "Connect!"
FILES="/tmp/initialize_sql/*.sql"
for file in $FILES;
do
mysql -h127.0.0.1 -uroot -p$MYSQL_ROOT_PASSWORD < $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment