carl crott
carl crott

Reputation: 753

Populate mysqldump data into a table: only for rows which exist in a given database

  1. Old database with out inforation
  2. Refactored database with a number of removed columns

I'd like to dump the old database, and repopulate the new DB.

... But only if the new database has a given column

Example:

Is there a mass operation which I can run to ONLY populate Login, Email and Phone only ?

Upvotes: 0

Views: 224

Answers (2)

carl crott
carl crott

Reputation: 753

So a modified working version of Marc B's statement is here:

INSERT INTO asdf_mock.citations_sites (`citation_id`, `site_id`, `created_at`, `updated_at`) 
   SELECT `citation_id`, `site_id`, `created_at`, `updated_at` 
   FROM asdf_production.citations_sites;

Running this with the back-tick quotes gives the desired insertion.

Upvotes: 0

Marc B
Marc B

Reputation: 360572

Assuming the two DBs are running within the same mysql instance, you can do

INSERT INTO newdb.newtable (field1, field2, ....)
    SELECT FROM olddb.oldtable (field1, field2, ...)

as a single query. No need to use a dump. Relevant docs here: http://dev.mysql.com/doc/refman/5.1/en/insert-select.html

Upvotes: 3

Related Questions