#!/bin/bash

BACKUPLOCATION=/var/local/mysqlbackups

mkdir -p $BACKUPLOCATION

# back up all the mysql databases, into individual files so we can later restore
# them separately if needed.
mysql --defaults-extra-file=/root/.my.cnf -B -N -e "show databases" | while read db
do
   BACKUPFILE=$BACKUPLOCATION/$db.sql
   echo "Backing up $db into $BACKUPFILE"
   /usr/bin/mysqldump --defaults-extra-file=/root/.my.cnf $db > $BACKUPFILE
done

.My.cnf

[client]
user=sql_user
password=passwd_sql
protocol=tcp
mysql -u username -p
USE bacula;
TRUNCATE TABLE Log;