Splitting a database dump

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/" {*}

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;

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.

One thought on “Splitting a database dump

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please copy the string yJCOYK to the field below: