While the method there with juggling grants works fine, I'd like to highlight another way that I think is much simpler: use grep & sed to create a file which contains only the table you want to restore.
mysql> show tables;
+------------------+
| Tables_in_gtowey |
+------------------+
| t1 |
| t2 |
| t3 |
+------------------+
3 rows in set (0.00 sec)
# mysqldump gtowey > dump.sql
Given 3 tables in a mysqldump file, lets restore just t2
# grep -n 'Table structure' dump.sql
19:-- Table structure for table `t1`
40:-- Table structure for table `t2`
61:-- Table structure for table `t3`
Now just use the line numbers to extract the table with sed:
sed -n '40,61 p' dump.sql > t2.sql
That's it, you have everything you need with no cleanup of mysql grants to do afterward.
9 comments:
Hi!
nice trick, thanks!
I used the perl script posted here and found that it works very well:
http://blog.tsheets.com/2008/tips-tricks/extract-a-single-table-from-a-mysqldump-file.html
Hey that is pretty nifty - Thanks for sharing!
Good.
There is another way I used. for database.
http://adminlinux.blogspot.com/2009/11/extract-single-dbtable-from-dump-file.html
thanks, saved my time
Very. Thanks!
I've developed a PHP script that allow users to browse dump files and extract single tables. http://mattkendrick.com/development/new-tool-mysqldump-browser/
I always revisit this post when I need to do perform such a tast... very slick.
briliant
Post a Comment