User Tools

Site Tools


info:mysql:database:backup

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}
do
    mysqldump --add-drop-table -u${USER} -p${PASS} ${DB} > ${DB}_${DATE_YMD}.sql &
    bzip2 ${DB}_${DATE_YMD}.sql &
    # sleep 10 # optional
done
wait # for child processes to end
info/mysql/database/backup.txt · Last modified: 2013-02-04 23:17 (external edit)