User Tools

Site Tools

Please note, that this is an old archived version of this site. Check out the new version at!

MySQL: Backup

Export a Database

# set or replace the variables $USER, $PASS and $DB
mysqldump --add-drop-table -u${USER} -p${PASS} ${DB}

Export all Databases individually

# set or replace the variables $USER and $PASS
DATE_YMD=$(date "+%Y-%m-%d")
DATABASES=$(mysql --batch -u${USER} -p${PASS} mysql --execute='show databases')
for db in ${DATABASES}
    mysqldump --add-drop-table -u${USER} -p${PASS} ${DB} > ${DB}_${DATE_YMD}.sql &
    bzip2 ${DB}_${DATE_YMD}.sql &
    # sleep 10 # optional
wait # for child processes to end
info/mysql/database/backup.txt · Last modified: 2013-02-04 22:17 (external edit)