Skip to main content
Home
badllama.com
  • Search
  • Log In

MySQL Dump - One File Per Table

bchavet's picture

Tue, 04/24/2012 - 15:41 by bchavet

#!/bin/bash

if [ "$1" == "" ]; then
    echo "Usage: $0 <database> [output-path]"
    exit 1
fi

TABLES=`mysql -B -N -e "select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA='$1'"`

OUT="$2"
if [ "$OUT" == "" ]; then
    OUT="."
fi
if [ ! -d $OUT ]; then
    echo "$OUT does not exist"
    exit 1
fi

for table in $TABLES; do
    echo -n "dumping $1.$table..."
    mysqldump $1 $table | gzip > $OUT/$1.$table.sql.gz
    echo "done"
done
Powered by Backdrop CMS