MySQL: export and import

DB_HOST=localhost
DB_NAME=db1
DB_USER=root
DB_PASS=pass1234
TARGET=/tmp
 
# export DB
mysqldump --host=${DB_HOST} --password=${DB_PASS} --user=${DB_USER} ${DB_NAME} | bzip2 --best > ${TARGET}/$(hostname -f)_${DB_NAME}_$(date -I).sql.bz2
 
# import DB
bzcat /tmp/db_dump_${DB_NAME}.sql.bz2 | mysql --host=localhost --user=${DB_USER} --password=${DB_PASS} ${DB_NAME}
mysql --host=localhost --user=${DB_USER} --password=${DB_PASS} ${DB_NAME} < dump.sql
 
# import bzip2 compressed file
bzip2 -dc dump.sql.bz2 | mysql --user=${DB_USER} --password=${DB_PASS} ${DB_NAME}