Splitting a database dump

This is a way to split a SQL dump into tables that is relatively easy. test

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/2012/05/2012/05 meaningful names:

for FILE in `ls -1 table*`; do
NAME=`head -n1 $FILE | cut -d$'x60' -f2`
mv $FILE "$NAME.sql";

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

Comments are closed.