2022 m. vasario 28 d., pirmadienis

large mysql db load

 zr more

 #!/bin/bash


DATA="/db.sql.gz"

SIZE="$(du $DATA | awk '{ print $1 }')K"

DBNAME="test"

DBPASS="Asdddsd"

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


Komentarų nėra:

Rašyti komentarą