选择性从CSV导入到MySQL [英] Selective Import from CSV to MySQL

查看:79
本文介绍了选择性从CSV导入到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将大型csv档案中的特定列汇入MySQL表格。
我知道如何导入所有的数据,但我的问题是我的csv文件太大,我不需要所有的数据,它拥有。

How would I import certain rows from a large csv file into a MySQL table. I know how to import all the data but my problem is that my csv file is too large and I don't need all the data that it has.

我只想导入COLUMN_X具有这些值[VALID1,VALID2,VALID3]的行。
应该忽略column_x的所有其他具有无效值的行。

I only want to import rows where the "COLUMN_X" has either of these values [VALID1, VALID2, VALID3] All other rows with invalid values for column_x should be ignored.

任何人都可以帮我做到这一点?
非常感谢。

Can anyone help me do that? Thanks a lot.

推荐答案

不能使用LOAD DATA INFILE过滤掉行,通过预处理CSV文件或将数据加载到临时表中,并将相关行插入到您的主表中,类似

You can't filter out rows with the LOAD DATA INFILE, so either filter these out by pre-processing the CSV file or load the data into a temporary table and insert the relevant rows into your main table, something like;

CREATE TEMP TABLE import LIKE my_main_table;
LOAD DATA LOCAL INFILE 'myfile.csv' into import;
INSERT INTO my_main_table SELECT * FROM import
                          WHERE column_x IN(VALID1, VALID2, VALID3)

这篇关于选择性从CSV导入到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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