#!/bin/bash
MYUSER=root
MYPASS=password
SOCKET="/var/lib/mysql/mysql.sock"
MYCMD="mysql -u $MYUSER -p$MYPASS"
MYDUMP="mysqldump -u $MYUSER -p$MYPASS"
BACKUP_DIR="/work/backup/mysql"

for database in `$MYCMD -e "show databases;"|sed '1,2d' |egrep -v "mysql|schema"`
do
    if [ ! -f $BACKUP_DIR/${database} ]; then 
        mkdir -p  $BACKUP_DIR/${database}
    fi
    $MYDUMP ${database} |gzip > $BACKUP_DIR/${database}/${database}_`date +%F`.tar.gz

done