user213154
user213154

Reputation:

Load data from two (or more) files into one table

I have one table:

CREATE TABLE t (
  id INT NOT NULL PRIMARY KEY,
  x INT NOT NULL,
  y INT NOT NULL );

The data is in two files: One file has (id, x) value pairs and another file has (id, y) value pairs. There are about 20 million rows in each. Most of the id values that appear in the x file also appear in the y file and visa versa.

Can you suggest how to load the id, x and y values from the two files into t?

Upvotes: 0

Views: 323

Answers (2)

kevpie
kevpie

Reputation: 26108

If you are on a unix machine you may have access to "join" which can join your 2 files together and produce them on stdout. Bulk load the standard out directly into mysql. This will reduce the number of writes to disk.

Upvotes: 1

Mchl
Mchl

Reputation: 62395

Load each of the files into two separate tables using LOAD DATA INFILE. Then use INSERT INTO ... SELECT to insert data into table t.

Upvotes: 0

Related Questions