如何使用load data Infile插入到多个表中?
我使用一个 python 程序,它将许多新条目插入到数据库中, 这些新条目分布在多个表中。
我正在使用 load data infile 来加载文件,但此解决方案仅适用于一张表,而且我不想多次执行此操作。
我发现 http://forge.mysql.com/worklog/task.php? id=875 这个,但我不太清楚 确定它是否已经实施。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我正在做的正是您想要做的事情,如下所示:
第 1 步:创建一个临时表(保存导入文件的所有字段)
第 2 步:加载本地数据内文件->插入临时表
第 3 步: INSERT INTO
Table1
( fieldlist ) SELECT FROMTempTable
( matching fieldlist ) ...根据需要包括 JOINS、WHERE 和 ON PRIMARY KEY UPDATE第 4 步:使用第二个表插入查询重复第 3 步,依此类推。
使用这种方法,我目前正在导入每个 22MB 数据文件,并将它们解析为多个表(6 个表,包括 2 个审核/更改表)。
在不知道您的表结构和数据文件结构的情况下,很难为您提供更详细的信息解释,但我希望这可以帮助您开始
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 FROMTempTable
( matching fieldlist ) ... include JOINS, WHERE, and ON PRIMARY KEY UPDATE as necessaryStep 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