MySQL: export and import

#!/bin/bash
 
# parameter
DB_HOST=db.2003.example.com
DB_NAME=cms1
DB_USER=dbo12345
DB_PASS=terceS
TARGET=~/export
 
# create target directory if not exists
[ ! -d ${TARGET} ] && mkdir ${TARGET}
 
# export database
mysqldump --host=${DB_HOST} --password=${DB_PASS} --user=${DB_USER} ${DB_NAME} | bzip2 --best > ~/export/export_${DB}_`date -I`.sql.bz2;
 
#
# import
#
# BASH
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}