Export MySQL database

#!/bin/bash
 
# parameter
HOST=YOUR_HOST_NAME
DB=YOUR_DB_NAME
USER=YOUR_DB_USER
PASS=YOUR_DB_PASS
TARGET=~/export
 
# create target directory if not exists
[ ! -d ${TARGET} ] && mkdir ${TARGET}
 
# export database
mysqldump --host=${HOST} --password=${PASS} --user=${USER} ${DB} | bzip2 --best > ~/export/export_${DB}_`date -I`.sql.bz2;
 
# import
mysql --host=localhost --user=dboxxxxxxxxx --password=******** dbxxxxxxxxx < dump.sql

Do you like this page? Then support it. Please click the AD below and visit the sponsor. Thank you!