#!/bin/bash
DATA="/db.sql.gz"
SIZE="$(du $DATA | awk '{ print $1 }')K"
DBNAME="test"
DBPASS="Apasdasdasdfnti"
DBUSER="root"
{
#echo "Dropping/creating database ${DBNAME}" >&2
#echo "DROP DATABASE IF EXISTS ${DBNAME};"
#echo "CREATE DATABASE ${DBNAME};"
echo "use ${DBNAME};"
echo "Setting speed settings" >&2
echo "SET FOREIGN_KEY_CHECKS = 0;"
echo "SET UNIQUE_CHECKS = 0;"
echo "SET AUTOCOMMIT = 0;"
echo "Loading data (this will take a while)" >&2
cat $DATA | gzip -d
echo "Resetting speed settings" >&2
echo "SET FOREIGN_KEY_CHECKS = 1;"
echo "SET UNIQUE_CHECKS = 1;"
echo "COMMIT;"
echo "Done." >&2
} | pv -ps $SIZE | mysql --password=$DBPASS --user=$DBUSER
#paprastas 1 eilutes pvz
# pv /home/dnsb/dbtest.sql.gz | gunzip | mysql --password=Apdasdadti --user=root dbname
# pv dump.sql.gz | zcat | mysql -u user -ppasswd database
#nblogask itas pvz https://github.com/servercollective/import-large-mysql-dump/blob/master/import.sh
#ddl="$ddl set global net_buffer_length=1000000; "
#ddl="$ddl set global max_allowed_packet=1000000000; "