I have a products table in a mysql.sql file. I wish to extract that one table and place it in it's own file. How would you go about doing this?
I ran into that problem a while ago and wrote a Perl script. It worked well, but it was an older version of MySQL. Call it like:extract.pl -table=TABLENAME mysqldumpfile.sql > recovered_table.sql
#!/usr/bin/perl -s -wnl #extract a single table from a mysql dump BEGIN { $table or warn "Usage: $0 -table=TABLE_TO_EXTRACT mysqldumpfile.sql" and exit 1; } /^DROP TABLE IF EXISTS `$table`/ .. /^UNLOCK TABLES;$/ and print;
I found this nice solution, you have to download this script on your server and type
$> ./MyDumpSplitter.sh yourfile.sql your_table_name
This will extract your table into your_table_name.sql
Optionnal
Now you can rename it using this type of command
$> sed -i 's/`your_table_name`/`your_table_name2`/g' your_table_name.sql
And re-injecting it with
mysql> source your_table_name.sql;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With