Create mysql database dump from bash

The following one liner can create a bzip2 archive of the mysql dump:

mysqldump -u$USER -p$PWD $DBNAME | bzip2 -c > $DBNAME.tar.bz2

Or use the following for a time stamped backup:

#mysqldump -u$USER -p$PWD $DBNAME | bzip2 -c > $DBNAME_$(date -d "today" +"%Y_%m_%d_%H%M").tar.bz2


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.