Restoring a Specific Table from a MySQL Dump
When working with large MySQL backup files containing multiple tables, restoring only a specific table can be a time-consuming task. In such cases, editing the entire dump file to extract the desired table may not be practical.
Using sed to Extract the Table
One effective approach to address this issue is to utilize the sed command in Linux or Unix operating systems. sed allows you to search and edit text files. Here's how you can isolate a particular table from a full MySQL dump:
$ sed -n -e '/CREATE TABLE.*`mytable`/,/Table structure for table/p' mysql.dump > mytable.dump
This command searches for the text string CREATE TABLE followed by mytable and copies everything up to the next CREATE TABLE line into a new file named mytable.dump.
$ mysql -u username -p database_name < mytable.dump
The above is the detailed content of How Can I Efficiently Restore a Single Table from a Large MySQL Dump File?. For more information, please follow other related articles on the PHP Chinese website!