2

I use aa python program which inserts many new entries to database, this new entries are spread across multiple tables.

I'm using load data infile to load the file, but this solution is only for one table, and I don't feel like to do this multiple times.

I found http://forge.mysql.com/worklog/task.php?id=875 this but I'm not quite sure if its already implemented or not.

3 Answers 3

3

I am doing exactly what you are trying to do as follows:

Step 1: Create a temp table (holding all the fields of the import file)

Step 2: LOAD DATA LOCAL INFILE -> into the temp table

Step 3: INSERT INTO Table1 ( fieldlist ) SELECT FROM TempTable ( matching fieldlist ) ... include JOINS, WHERE, and ON PRIMARY KEY UPDATE as necessary

Step 4: Repeat step 3 with the second table insert query and so on.

Using this method I am currently importing each of my 22MB data files, and parsing them out to multiple tables (6 tables, including 2 audit/changes tables)

Without knowing your table structure and data file structure it is difficult to give you a more detailed explanation, but I hope this helps get you started

Sign up to request clarification or add additional context in comments.

1 Comment

On a side note, this isn't a 1 pass solution, you will create 1 query (or more) on the temp table for each table you are updating. In my situation I created one for each table, and for my audit tables I created one query for each table column I am auditing. The processing speed on my 22 meg data file is less than 15 seconds to process 30000 records into 6 tables (8 insert queries). I don't know if this is a great speed but in my opinion I am more than happy with that speed.
2

load data from local file to insert new data accross multiple tables isnt yet supported (v 5.1)

Comments

0

I don't think LOAD DATA can do that, but why not duplicate the table after importing?

See

1 Comment

those new data im trying to write into mysql table arent already in table ... so duplicating table wont work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.