[prev in list] [next in list] [prev in thread] [next in thread]
List: mysql
Subject: How to split a mysqldump file of multiple databases to singlefile databases... SOLVED with script
From: Andrés_Tello <mr.criptos () gmail ! com>
Date: 2012-02-20 17:41:28
Message-ID: CAErsY8uWAtH+5PGd9voPGk_PWNzhtaKJjhT=BLci2of0ZhDULA () mail ! gmail ! com
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic