Skip to main content
Post Undeleted by Alex
added 707 characters in body
Source Link
Alex
  • 1.2k
  • 1
  • 9
  • 11

This is what I ended up doing to split the single-table dump into one file per row, named by ID:

awk -F',' '/^INSERT/{print > gensub("[^0-9]"".*\\(","", "G", $15)".txt"sql"}' mytable../big.sql 

Where my table has around 15 fields. This takes the 15th column, separated by "," and replaces out the remaining SQL part (there are more elegant ways to do this, works only because I have numeric-only identifiers)

This is full script - I happen to have only one such table, so it misses the logic of the other answer

#!/bin/bash
DBNAME=example
BIGTABLE=big

mysqldump $DBNAME --single-transaction --quick --complete-insert --skip-extended-insert --ignore-table=$DBNAME.$BIG | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > sql/master.sql

rm -rf sql/master.d
mkdir sql/master.d

mysqldump $DBNAME --hex-blob --single-transaction --quick --complete-insert --skip-extended-insert $BIG | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > sql/master.d/$BIG.sql

cd sql/master.d/
mkdir $BIG.d
cd $BIG.d

awk -F',' '/^INSERT/{print > gensub(".*\\(","", "G", $15)".sql"}' ../$BIG.sql
rm ../$BIG.sql

This is what I ended up doing to split the single-table dump into one file per row, named by ID:

awk -F',' '/^INSERT/{print > gensub("[^0-9]","", $15)".txt"}' mytable.sql 

Where my table has around 15 fields. This takes the 15th column, separated by "," and replaces out the remaining SQL part (there are more elegant ways to do this, works only because I have numeric-only identifiers)

This is what I ended up doing to split the single-table dump into one file per row, named by ID:

awk -F',' '/^INSERT/{print > gensub(".*\\(","", "G", $15)".sql"}' ../big.sql

Where my table has around 15 fields. This takes the 15th column, separated by "," and replaces out the remaining SQL part (there are more elegant ways to do this, works only because I have numeric-only identifiers)

This is full script - I happen to have only one such table, so it misses the logic of the other answer

#!/bin/bash
DBNAME=example
BIGTABLE=big

mysqldump $DBNAME --single-transaction --quick --complete-insert --skip-extended-insert --ignore-table=$DBNAME.$BIG | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > sql/master.sql

rm -rf sql/master.d
mkdir sql/master.d

mysqldump $DBNAME --hex-blob --single-transaction --quick --complete-insert --skip-extended-insert $BIG | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > sql/master.d/$BIG.sql

cd sql/master.d/
mkdir $BIG.d
cd $BIG.d

awk -F',' '/^INSERT/{print > gensub(".*\\(","", "G", $15)".sql"}' ../$BIG.sql
rm ../$BIG.sql
Post Deleted by Alex
added 213 characters in body
Source Link
Alex
  • 1.2k
  • 1
  • 9
  • 11

This is what I ended up doing to split the single-table dump into one file per row, named by ID:

awk -F',' '/^INSERT/{gsubprint > gensub("[^0-9]","", $15); print > $15"".txt"}' mytable.sql 

Where my table has around 15 fields. This takes the 15th column, separated by "," and replaces out the remaining SQL part (there are more elegant ways to do this, works only because I have numeric-only identifiers)

This is what I ended up doing to split the single-table dump into one file per row, named by ID:

awk -F',' '/^INSERT/{gsub("[^0-9]","", $15); print > $15".txt"}' mytable.sql 

This is what I ended up doing to split the single-table dump into one file per row, named by ID:

awk -F',' '/^INSERT/{print > gensub("[^0-9]","", $15)".txt"}' mytable.sql 

Where my table has around 15 fields. This takes the 15th column, separated by "," and replaces out the remaining SQL part (there are more elegant ways to do this, works only because I have numeric-only identifiers)

Post Undeleted by Alex
Post Deleted by Alex
Source Link
Alex
  • 1.2k
  • 1
  • 9
  • 11

This is what I ended up doing to split the single-table dump into one file per row, named by ID:

awk -F',' '/^INSERT/{gsub("[^0-9]","", $15); print > $15".txt"}' mytable.sql