List:General Discussion« Previous MessageNext Message »
From:Andrés Tello Date:February 20 2012 5:41pm
Subject:How to split a mysqldump file of multiple databases to singlefile
databases... SOLVED with script
View as plain text  
Today I needed to split a mysqldump -A into it several databases.
I didn't have access to the original source, so I only had the texr file to
work.
It was a webhosting server dump, so there was a LOT of databases...

I split the file with this little script I made:

file=<myqdl dump file>
nextTable=""
nextStart=0
nextEnd=0
lastTable=""
lastStart=0

for i in `grep -n "^CREATE DATABASE" $file | awk '{print $1":"$7}' | sed
"s/CREATE://g"`
do
i=`echo $i | sed "s/\\\`//g"`
nextTable=`echo $i | cut -d : -f 2`
nextStart=`echo $i | cut -d : -f 1`

nextEnd=$(( $nextStart -1 ))


if [ "$lastTable" != "" ]
then
  echo "Tabla: $lastTable from: $lastStart to $nextEnd"
  sed -n ${lastStart},${nextEnd}p  $file > new/$lastTable.portabla.sql
fi

lastTable=$nextTable
lastStart=$(( $nextStart ))

done

Thread
How to split a mysqldump file of multiple databases to singlefiledatabases... SOLVED with scriptAndrés Tello20 Feb