开发者

How to use load data Infile to insert into multiple tables?

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.


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


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


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

See

  • Duplicating table in MYSQL without copying one row at a time
  • Or, if you can go outside mySQL, Easiest way to copy a MySQL database?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜