This is a way to split a SQL dump into tables that is relatively easy.
It should start with zcat FILE.gz | csplit -ftable – “/DROP TABLE/” {*},
but csplit has bug where reading a lot from standard in does not work.
So instead unzip your file first.
gunzip FILE.gz
csplit -ftable FILE "/DROP TABLE/" {*}
csplit -ftable FILE "/DROP TABLE/" {*}
Then to give the files meaningful names:
for FILE in `ls -1 table*`; do
NAME=`head -n1 $FILE | cut -d$'\x60' -f2`
mv $FILE "$NAME.sql";
done;
NAME=`head -n1 $FILE | cut -d$'\x60' -f2`
mv $FILE "$NAME.sql";
done;
If your dump does not start witjh a DROP TABLE `name` IF EXISTS,
you will have to change the match expression to csplit a litte.
Hope this is useful to someone.
Yes, you’re helping me :) The way I was doing it pretty much sucked.
I worked it into a little bash script: https://gist.github.com/1608062
The script also cuts off the header and footer and adds them to each sql file.
@ http://twitter.com/ArnoldDaniels