Skip to content

Instantly share code, notes, and snippets.

@tarnagas
Last active February 20, 2019 14:55
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 tarnagas/548eb7d3a02138de6b62e2c1e3a28b5e to your computer and use it in GitHub Desktop.
Save tarnagas/548eb7d3a02138de6b62e2c1e3a28b5e to your computer and use it in GitHub Desktop.
Import dump generated by mysqlpump
#!/usr/bin/env sh
# Sample of use:
#
# ```sh
# sh import.sh backuped_database.sql
# ```
#
# @see https://hub.docker.com/r/mysql/mysql-server/
# @see https://dev.mysql.com/doc/refman/8.0/en/mysqlpump.html
set -eu
test -f "$1" || exit 2 # ENOENT
tmpfile=$(mktemp /tmp/mysql-import.XXXXXX)
cat "$1" | \
perl -pe 's#`saved_database`.##g' | \
perl -pe "s#^USE\s+.*##" | \
perl -pe 's#ALGORITHM=(.*) DEFINER=`(.*)`@`(.*)` SQL SECURITY DEFINER##' \
> "$tmpfile"
cat "$tmpfile" | \
mysql -hlocalhost -uroot -p"${MYSQL_ROOT_PASSWORD}" "${MYSQL_DATABASE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment