You can't do it in a single command into separate files.
This is the script I use to create backups from a MySQL server. In this case the server is a replication slave which is why the options are there to turn off the replication before the backup and turn it back on afterwards.
The databases are listed individually in DBLIST variable to give control over exactly what is backed up.
I use it with the "day name" BACKUPDATE so that I end up with 7 days worth of backups.
Once all the databases have been dumped the SQL files are then compressed.
You can put your username and password etc. into the DUMPOPTIONS variable as needed.
Code:
#!/bin/bash
# Options
# BACKUPDIR Location to store backups
# DBLIST Space separated list of database names to backup
# DUMPOPTIONS Any options you wish mysqldump to use
# BINDIR Path to executables
BACKUPDIR=/backup
DBLIST="mydatabase1 myforumdatabase mywordpressdatabase"
DUMPOPTIONS="--lock-all-tables"
BINDIR=/usr/bin
## Script Logic Starts Here
echo `date` MySQL Backup START
# Date to append to database names
# Uncomment the line below to use full dates
# Remember to make the day of week line a comment if you want to use the full dates.
#BACKUPDATE=`/bin/date +%Y%m%d`
# The versions gives day of the week backups, eg mydatabase.Mon.sql, mydatabase.Tue.sql
BACKUPDATE=`/bin/date +%a`
# Stop accepting replication while we backup
echo `date` Stop replication
${BINDIR}/mysqladmin stop-slave
# Iterate through the list of databases and take a dump
for DATABASE in ${DBLIST} ; do
echo `date` Dumping ${DATABASE} START
${BINDIR}/mysqldump ${DUMPOPTIONS} ${DATABASE} > ${BACKUPDIR}/${DATABASE}_${BACKUPDATE}.sql
echo `date` Dumping ${DATABASE} FINISH
done
# Start accepting replication
echo `date` Start replication
${BINDIR}/mysqladmin start-slave
# Compress the backups
echo `date` Compress Backup START
${BINDIR}/gzip ${BACKUPDIR}/*_${BACKUPDATE}.sql
echo `date` Compress Backup FINISH
# Thank you and goodnight
echo `date` MySQL Backup FINISH