Restoring a Single Table from a Full MySQL Mysqldump File
Question:
Is it feasible to restore only a specific table from a large (approximately 440 megabyte) MySQL mysqldump backup that contains all tables?
Answer:
Yes, it is possible to extract a single table from a full mysqldump file.
Method:
Utilize the sed command to isolate the relevant table data. For example, to restore a table named "mytable" from a backup file named "mysql.dump":
$ sed -n -e '/CREATE TABLE.*`mytable`/,/Table structure for table/p' mysql.dump > mytable.dump
This command will generate a file called "mytable.dump" that contains the table's structure and data (a series of INSERT statements) that are located between the "CREATE TABLE mytable" and the next "CREATE TABLE" statement.
After modifying the "mytable.dump" file to ensure its completeness and accuracy, you can restore the table using the following command:
mysql -u USERNAME -pPASSWORD DATABASE_NAME < mytable.dump
The above is the detailed content of How Can I Restore a Single Table from a Full MySQL Dump File?. For more information, please follow other related articles on the PHP Chinese website!