如何使用load data Infile插入到多个表中?

发布于 09-29 13:01 字数 287 浏览 6 评论 0原文

我使用一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

落花随流水2024-10-06 13:01:54

我正在做的正是您想要做的事情,如下所示:

第 1 步:创建一个临时表(保存导入文件的所有字段)

第 2 步:加载本地数据内文件->插入临时表

第 3 步: INSERT INTO Table1 ( fieldlist ) SELECT FROM TempTable ( 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 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

深空失忆2024-10-06 13:01:54

尚不支持从本地文件加载数据以跨多个表插入新数据(v 5.1)

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

你穿错了嫁妆2024-10-06 13:01:54

我不认为 LOAD DATA 可以做到这一点,但为什么不在导入后复制表呢?

请参阅

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

See

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文