Skip to content

Instantly share code, notes, and snippets.

@akumbhani66
Created December 13, 2020 06:02
Show Gist options
  • Save akumbhani66/f8efb59da05a2eb90e5ef0adf6a277d0 to your computer and use it in GitHub Desktop.
Save akumbhani66/f8efb59da05a2eb90e5ef0adf6a277d0 to your computer and use it in GitHub Desktop.
Dump entire db to tsv/csv
#!/bin/bash
host=host
uname=uname
pass=pwd
port=port
db=db
DATE=`date +%Y%m%d`
rm -rf $DATE
echo 'show tables' | mysql -B -h${host} -u${uname} -p${pass} -P${port} ${db} > tables.txt
awk 'NR>1' tables.txt > tables_new.txt
while IFS= read -r line
do
mkdir -p $DATE/$line
echo "select * from $line" | mysql -B -h"${host}" -u"${uname}" -p"${pass}" -P"${port}" "${db}" > $DATE/$line/dump.tsv
done < tables_new.txt
touch $DATE/$DATE.fin
rm -rf tables_new.txt tables.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment