Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mysql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ADD my.cnf /etc/mysql/mysql.cnf

# MTK - A toolkit for exporting, sanitizing and packaging MySQL database.
# https://github.com/skpr/mtk
COPY --from=ghcr.io/skpr/mtk:v2.1.1 /usr/local/bin/mtk /usr/local/bin/mtk
COPY --from=ghcr.io/skpr/mtk:v2.3.0 /usr/local/bin/mtk /usr/local/bin/mtk

USER mysql

Expand Down
22 changes: 16 additions & 6 deletions mysql/scripts/database-import-tables
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

DATABASE=$1
DUMP_DIR=$2
MAX_CONCURRENT=4

mysql-drop-tables ${MYSQL_USERNAME} ${MYSQL_PASSWORD} ${MYSQL_HOSTNAME} ${DATABASE}

for i in ${DUMP_DIR}/*.sql
do
echo "Starting to import: $i"
# define the worker function
import_sql() {
local sqlfile="$1"
echo "Starting to import: $sqlfile"
start=$(date +%s)
MYSQL_PWD="${MYSQL_PASSWORD}" mysql --user=${MYSQL_USERNAME} --host=${MYSQL_HOSTNAME} ${DATABASE} < $i
MYSQL_PWD="${MYSQL_PASSWORD}" mysql --user=${MYSQL_USERNAME} --host=${MYSQL_HOSTNAME} ${DATABASE} < $sqlfile
end=$(date +%s)
echo "Finished importing $i in: $(($end-$start)) seconds"
done
echo "Finished importing $sqlfile in: $(($end-$start)) seconds"
}
export -f import_sql
export DATABASE
export MYSQL_HOSTNAME
export MYSQL_USERNAME
export MYSQL_PASSWORD

find "$DUMP_DIR" -type f -name '*.sql' -print0 \
| xargs -0 -n1 -P"$MAX_CONCURRENT" bash -c 'import_sql "$@"' _