Monday, 24 March 2014

Extract a single table from a mysqldump

We may have the full backup of our database, at certain scenario we need a particular table only from our database. There are many ways to achieve it, in which it will take more time to complete.
 In the below steps i have given to extract a particular table (CountryLanguage from world database) from our database which will be very easy and fast.
Step 1: cat dump.sql | grep -n "Table structure"

Step 2: sed -n '[starting_line_number] , [ending_line_number] p' 
            [dump_filename].sql > [table_output_filename].sql
When you view that dumped file using less command you will be able to find
only the structure for CountryLanguage table.

      less test.sql
Step 3:  mysql db_name < [table_output_filename].sql

 Now you can restore your single table to your database.

Through this way you can extract a single table from a database.

Hope it helped,............ Thank you...............