Quickly Restore a table _ MySQL from the mysqldump file

Source: Internet
Author: User
Quickly Restore a table named mysqldump from the mysqldump file

BitsCN.com

Quickly Restore a table from the mysqldump file

In many cases, we need to restore a table from the mysqldump backup file. the common practice is to restore the SQL file to a test database and then use mysqldump to export a table, restore to the production environment. in this way, if the data volume is small, this method is feasible, but you still need to have a test machine or create a database temporarily, which is not very convenient, the method described below avoids the above problems:

1. use awk

You can first use 'Show tables; 'in the original database to view the list of database tables. Note that the list has been sorted alphabetically, for example,

Table1

Table 2

Table 3

Then use awk to filter SQL statements. if you want to restore table 2, you can use the following statement.

 ]# awk ‘/^-- Table structure for table .table2./,/^-- Table structure for table .table3./{print}’ mydumpfile.sql > /tmp/recovered_table.sql

2. use sed

Same method as above

Suppose you want to restore table 2, you can use the following statement

cat mydumpfile.sql | sed -n -e '/Table structure for table .test1./,/Table structure for table .test2./p' > /tmp/extracted_table.sql

Then, the filtered. SQL file is imported into the database and restored.

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.