Last active
February 20, 2019 14:55
-
-
Save tarnagas/548eb7d3a02138de6b62e2c1e3a28b5e to your computer and use it in GitHub Desktop.
Import dump generated by mysqlpump
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 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