databases='test1 test2' Date=$(date "+%Y-%m-%d") Time=$(date "+%H%M%S") for db in $databases do mkdir -p `echo /home/backup/mysql/$db/$Date` done for db in $databases do tables=`mysql -u root -p123456 $db -e "show tables"` for table in $tables do mysqldump -u root -p123456 $db $table > /home/backup/mysql/$db/$Date/${table}_$Time.sql done done