Home > Database > Mysql Tutorial > How Can I Restore a Single Table from a Full MySQL Dump File?

How Can I Restore a Single Table from a Full MySQL Dump File?

Linda Hamilton
Release: 2024-12-06 06:02:11
Original
398 people have browsed it

How Can I Restore a Single Table from a Full MySQL Dump File?

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template