Quick and Dirty MySQL Backup

So you need to backup all the MySQL databases on your system? This is easy with MySQL’s mysqldump. The quickest solution is to
dump all databases to one ugly file:

mysqldump -u root -p --all-databases > $(hostname)-everything.sql

A more organized approach is to loop through all your databases and dump individual files. A Bash script example:

read -p  "Enter MySQL user: " -s DBUSER
read -p  "Enter MySQL $DBUSER password: " DBPASS
DATE=$(date +'%m%d%Y')
# dump all databases to current path
for DB in $(echo "show databases" | mysql -u$DBUSER -p$DBPASS | grep -v Database); do
   mysqldump -u$DBUSER -p$DBPASS $DB > $DB-$DATE.sql || exit $?
   gzip $DB-$DATE.sql || exit $?
done && exit $?


MySQL.com: MySQL AB :: MySQL 5.0 Reference Manual :: 8.13 mysqldump A Database Backup Program