Search code examples
mysqldatabase-restore

Restoring selective tables from an entire database dump?


I have a mysql dump created with mysqldump that holds all the tables in my database and all their data. However I only want to restore two tables. (lets call them kittens and kittens_votes)

How would I restore those two tables without restoring the entire database?


Solution

  • Well, you have three main options.

    1. You can manually find the SQL statements in the file relating to the backed up tables and copy them manually. This has the advantage of being simple, but for large backups it's impractical.

    2. Restore the database to a temporary database. Basically, create a new db, restore it to that db, and then copy the data from there to the old one. This will work well only if you're doing single database backups (If there's no CREATE DATABASE command(s) in the backup file).

    3. Restore the database to a new database server, and copy from there. This works well if you take full server backups as opposed to single database backups.

    Which one you choose will depend upon the exact situation (including how much data you have)...