Backing up MySQL databases

Just a simple script that loops through all your MySQL databases and exports them to individual .sql files. Typically run as the MySQL root user, so be sure to remove your username and password from the file when you're done.

#!/bin/bash

# Don't leave your password laying around in a bash
# script - remove the credentials when you're done
# with the script.

USER=""
PASS=""

databases=`mysql -u $USER -p$PASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

for db in $databases; do
    if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
        echo "Dumping database: $db"
        mysqldump -u $USER -p$PASS --databases $db > `date +%Y%m%d`.$db.sql
    fi
done