If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Restoration of single table from mysqldump?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-17-03, 08:45
Mincer Mincer is offline
Registered User
 
Join Date: Sep 2003
Location: London
Posts: 56
Exclamation 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,
Reply With Quote
  #2 (permalink)  
Old 11-17-03, 12:18
aus aus is offline
Registered User
 
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?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On