Tuesday, November 27, 2007

MySQL Dump shell script


I found this script over at http://crazytoon.com/ just thought I would put it on my post-it site to remember.

#!/bin/bash
db=$1
if [ “$db” = “” ]; then
echo “Usage: $0 db_name”
exit 1
fi
mkdir $$
cd $$
clear
for table in `mysql $db -e ’show tables’ | egrep -v ‘Tables_in_’ `; do
echo “Dumping $table”
mysqldump –opt $db $table > $table.sql
done
if [ “$table” = “” ]; then
echo “No tables found in db: $db”
fi

No comments: