MySQL: export and import

DB_HOST=localhost
DB_NAME=db1
DB_USER=root
DB_PASS=pass1234

Export DB

mysqldump --host=${DB_HOST} --password=${DB_PASS} --user=${DB_USER} ${DB_NAME} | \
  bzip2 --best > $(hostname -f)_${DB_NAME}_$(date -I).sql.bz2
 
# export all databases
mysqldump --host=${DB_HOST} --port=${DB_PORT} --user=${DB_USER} --password=${DB_PASS} --all-databases | \
  bzip2 > db_$(date -I)_$(date +%F_%H%M%S).sql.bz2
 
# --no-tablespaces
# --lock-tables=false

Import DB

# from bz2
bzcat /tmp/db_dump_${DB_NAME}.sql.bz2 | mysql --host=localhost --user=${DB_USER} --password=${DB_PASS} ${DB_NAME}
# from sql
mysql --host=localhost --user=${DB_USER} --password=${DB_PASS} ${DB_NAME} < dump.sql

Import (bz2)

bzip2 -dc dump.sql.bz2 | mysql --user=${DB_USER} --password=${DB_PASS} ${DB_NAME}