简体   繁体   English

如何在PHP中实现MySQL ::“LOAD DATA LOCAL INFILE”?

[英]How to implement MySQL::“LOAD DATA LOCAL INFILE” in PHP?

We have to implement the import procedure. 我们必须实施导入程序。 The quantities of data is about 100 megabytes for one CSV files (the files already resides on server, so no upload necessary). 一个CSV文件的数据量约为100兆字节(文件已驻留在服务器上,因此无需上传)。

Any advice on whether to implement the bulk "LOAD DATA LOCAL INFILE" or row-by-row "INSERT/REPLACE" on importing data into database. 关于在将数据导入数据库时​​是否实现批量“LOAD DATA LOCAL INFILE”或逐行“INSERT / REPLACE”的任何建议。

I've checked that "LOAD DATA LOCAL INFILE" works mUUUch faster than a row-by-row import, BUT the row-by-row import gives the better control on reimport/update and so forth. 我已经检查过“LOAD DATA LOCAL INFILE”比逐行导入更快地工作mUUUch,但是逐行导入可以更好地控制重新导入/更新等等。

In some sense, could we benefit from both of the implementation, that is speed from the first one and control from the second? 从某种意义上说,我们可以从两个实施中受益,即第一个的速度和第二个的控制?

Any advice or completely different way to implement the import procedures, code snippets, database tricks are warmly appreciated. 任何建议或完全不同的方式来实现导入程序,代码片段,数据库技巧都受到热烈的赞赏。

Thank you! 谢谢!

No. Either you have full control over the process and let PHP do the insert, or you have it at full speed and let the MySQL client library handle it. 没有。要么您完全控制进程并让PHP执行插入操作,要么全速运行并让MySQL客户端库处理它。

What you can do is load it into an intermediate table and then perform a query that selects from that table and inserts it into the actual table. 可以做的是将其加载到中间表中,然后执行从该表中选择并将其插入实际表的查询。 This will allow you to do bulk manipulation of the data. 这将允许您对数据进行批量操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM