Skip to content

Instantly share code, notes, and snippets.

@carlosromero
Created July 5, 2011 16:31
Show Gist options
  • Save carlosromero/1065197 to your computer and use it in GitHub Desktop.
Save carlosromero/1065197 to your computer and use it in GitHub Desktop.
Mysql dump by tables
#!/bin/bash
USER=root
PASS=
DBNAME=mydb
DIRLOCAL=/home/user/dumps/
cd $DIRLOCAL
mkdir `date +%Y%m%d`
cd `date +%Y%m%d`
for table in `echo "show tables" | mysql -u $USER -p$PASS $DBNAME | grep -v ^mysql$ | grep -v ^Tables_in_$DBNAME$`;
do
#one file per table
mysqldump --add-drop-table --routines -u $USER -p$PASS $DBNAME ${table}> ${table}.sql;
done
gzip *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment