使用php将大型csv文件导入mysql数据库 [英] Import large csv file to mysql database using php

查看:157
本文介绍了使用php将大型csv文件导入mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的CSV文件(150 MB).将其导入MySQL的最佳方法是什么? 在将其插入MySQL表之前,我必须在PHP中进行一些操作.

I have a very large CSV file (150 MB). What is the best way to import it to MySQL? I have to do some manipulation in PHP before inserting it into the MySQL table.

推荐答案

您可以查看一旦将数据加载到MySQL中,您也许可以进行操作,而不是先将其读取到PHP中.首先使用LOAD DATA INFILE将原始数据存储在临时表中,然后使用如下语句将数据转换为目标表:

You might be able to do the manipulations once the data is loaded into MySQL, rather than first reading it into PHP. First store the raw data in a temporary table using LOAD DATA INFILE, then transform the data to the target table using a statement like the following:

INSERT INTO targettable (x, y, z)
SELECT foo(x), bar(y), z
FROM temptable

这篇关于使用php将大型csv文件导入mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆