Skip to content

Instantly share code, notes, and snippets.

@nikolazic
Created February 9, 2017 15:18
Show Gist options
  • Save nikolazic/b740a3e76ab750a1304a1ab2e8913b78 to your computer and use it in GitHub Desktop.
Save nikolazic/b740a3e76ab750a1304a1ab2e8913b78 to your computer and use it in GitHub Desktop.
Split MySQL dump SQL file into one file per table
#!/bin/bash
####
# Split MySQL dump SQL file into one file per table
# based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump
####
if [ $# -ne 1 ] ; then
echo "USAGE $0 DUMP_FILE"
fi
csplit -s -ftable $1 "/-- Table structure for table/" {*}
mv table00 head
for FILE in `ls -1 table*`; do
NAME=`head -n1 $FILE | cut -d$'\x60' -f2`
cat head $FILE > "$NAME.sql"
done
rm head table*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment