如何从csv文件中选择要导入数据库的字段?

时间:2015-05-21 12:38:49

标签: php mysql

LOAD DATA INFILE 
    'c:\sample data.csv' INTO TABLE
    companies(company_name,company_description) FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\r\n';

1 个答案:

答案 0 :(得分:0)

您可以在提及terminated by ...名称之前省略column语句或使用

示例1

LOAD DATA INFILE 
    'c:\sample data.csv' INTO TABLE
    companies(company_name,company_description);

示例2

LOAD DATA INFILE 
    'c:\sample data.csv' INTO TABLE
    companies
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\r\n'
    (company_name,company_description);

请参阅文档