简体   繁体   English

最佳实践:使用PHP 5.x将CSV导入MYSQL数据库

[英]Best Practice : Import CSV to MYSQL Database using PHP 5.x

what is the best solution to import large amounts of records into an MySQL or Oracle Database. 将大量记录导入MySQL或Oracle数据库的最佳解决方案是什么? I Think there are two ways : 我认为有两种方法:

  • Insert every record with an persistent connection 插入具有持久连接的每条记录
  • Create on BIG SQL-Statement and query the Database 在BIG SQL语句上创建并查询数据库

Iam not sure wich is performing better ? 我不确定性能是否更好? Is there any Best Practice Solutions for this kind of operation ?? 是否有针对此类操作的最佳实践解决方案?

There is one other possibility: LOAD DATA INFILE 还有另一种可能性: LOAD DATA INFILE

LOAD DATA LOCAL INFILE 'foobar.csv' 
INTO TABLE foobar
FIELDS TERMINATED BY ',' ENCLOSED BY '"' 
LINES TERMINATED BY '\r\n';

This requires that the MySQL server has access to the physical file. 这要求MySQL服务器有权访问物理文件。 But moving/copying a file to an import directory should not be hard with PHP. 但是,使用PHP并不难将文件移动/复制到导入目录。

Import into MySQL you can use LOAD DATA INFILE 导入MySQL可以使用LOAD DATA INFILE

http://dev.mysql.com/doc/refman/5.1/en/load-data.html http://dev.mysql.com/doc/refman/5.1/en/load-data.html

Must admit I tend to use MySQL Administrator for most of my large database restores. 必须承认,我倾向于对大多数大型数据库还原使用MySQL Administrator。 Not too sure about Oracle. 对Oracle不太确定。 Also depends on the size and structure of your MySQL. 还取决于MySQL的大小和结构。

I'm talking a couple of GBs of SQL data. 我说的是几GB的SQL数据。

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

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