title: How to split a big mysqldump file for get each structure and data separately?
body: <p>Based on <a href="https://gist.github.com/jasny/1608062#file-mysql_splitdump-sh" rel="nofollow noreferrer">https://gist.github.com/jasny/1608062#file-mysql_splitdump-sh</a></p>
  
  <pre><code>#!/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 [ $# -lt 1 ] ; then
    echo "USAGE $0 DUMP_FILE [TABLE]"
    exit
  fi
  
  if [ $# -ge 2 ] ; then
    csplit -s -ftable $1 "/-- Table structure for table/" "%-- Table structure for table \`$2\`%" "/-- Table structure for table/" "%40103 SET TIME_ZONE=@OLD_TIME_ZONE%1"
  else
    csplit -s -ftable $1 "/-- Table structure for table/" {*}
  fi
  
  [ $? -eq 0 ] || exit
  
  mv table00 head
  
  FILE=`ls -1 table* | tail -n 1`
  if [ $# -ge 2 ] ; then
    mv $FILE foot
  else
    csplit -b '%d' -s -f$FILE $FILE "/40103 SET TIME_ZONE=@OLD_TIME_ZONE/" {*}
    mv ${FILE}1 foot
  fi
  
  for FILE in `ls -1 table*`; do
    NAME=`head -n1 $FILE | cut -d$'\x60' -f2`
    cat head $FILE foot &gt; "$NAME.sql"
  done
  
  rm head foot table*
  </code></pre>
  
  <p>I want to split my big mysqldump file for get each table structure and table data separately.</p>
  
  <p>I'm no expert in bash script and I search the pattern for split the dump file to get several files like :</p>
  
  <ul>
  <li>table_one_structure.sql</li>
  <li>table_one_data.sql</li>
  <li>table_two_structure.sql</li>
  <li>table_two_data.sql</li>
  <li>etc ..</li>
  </ul>