how to dump all mysql databases

a simple script to copy all the databases on a server to another server…

#!/bin/sh
# mysql.dump.all.dbs - dump all mysql databases
# author: dave capella  <http:_grox.net/mailme>
# date  : 02/04/2013
# notes : requires mysqldump. root needs full priv's on all db's
############################################################
PRG=`basename $0`
today=`date +%Y%m%d`
dir=${dir:-/backup/mysql}
echo "backup directory: $dir"
user=${user:-root}
[ -d $dir ] || mkdir -p $dir
for db in `mysql -u $user -p$pass -Bse "show databases;"` ; do
        mysqldump -u $user -p$pass --opt $db | gzip > $dir/${db}-${today}.sql.gz
done

############################################################
# eof: mysql.dump.all.dbs                  vim:noet:ts=4 sts=4 sw=4 tw=80

to do a single database:

mysqldump -u root -pMYpassWord --opt dbname > dbname.dump.sql