I have a 15GB sql file which is a backup of a database. The problem I have is that half way through it, it failed. Luckily, I know which table to pick up from.

Is there a way I can split this SQL file by the starting point of the table I need to pick up from or perhaps get mysql to do this itself?



You could use sed to split the file using ranges

sed -n '/Start Text/,/End Text/p' >part.sql

This will start printing when /Start Text/ is found and will continue printing until /End Text/ or end of file is reached. Make sure Start Text is unique to the starting point and End Text isn't in the file.


You can use the split command (look into the line count option), or you can use dd with a byte offset (found using grep -b) to extract from your dumpfile as well.

Here's a blog post that covers that process (this is an answer I gave elsewhere on the site and decided to blog the solution).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.