Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Location
    London
    Posts
    56

    Exclamation Unanswered: Restoration of single table from mysqldump?

    How can I restore a single table from a database backup file created with mysqldump (with default settings)?

    Thanks,

    Matt,

  2. #2
    Join Date
    Oct 2003
    Location
    Denver, Colorado
    Posts
    137

    Re: Restoration of single table from mysqldump?

    You should comment out the CREATE DATABASE and USE statements in the dumpfile, then create a new database, use the SOURCE command to run your mysqldump file, then use a CREATE statement to copy the table that you want from the new database to your target database:

    CREATE DATABASE tempdb;
    USE tempdb;
    SOURCE databasebackups/mydump.sql;
    CREATE TABLE targetdb.targettable
    SELECT * FROM sourcetable;
    DROP DATABASE tempdb;

    If you have specific needs for the table structure that will not be copied over using the CREATE... SELECT statement, then you can either run an ALTER TABLE after or CREATE TABLE before manually. If it is going to be a lot of work to recreate the specifics of the table, then run mysqldump after the import to the new database to export only the table you want.

    mysqldump sourcedatabase sourcetable > new_table.sql

    You can then just use the mysqldump file on the target database. How does that sound?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •