如何将单列csv文件加载到mysql中的特定列中

时间:2016-02-11 10:30:47

标签: mysql

我有一个包含五列(id,name,age,number,email)的表,其中(列'id'是Pk并且具有auto_increment)和一个包含仅用于列的信息的单列csv文件数'。如何在mysql中加载此文件。

我试过这个但是没有用:

load data local infile 'C:/Users/user/Downloads/dnd_220116.csv'
into table testing FIELDS TERMINATED BY ','
ENCLOSED BY '"' LINES TERMINATED BY '\r\n' (@dummy,@dummy,number,@dummy); 

1 个答案:

答案 0 :(得分:0)

LOAD DATA LOCAL 
    INFILE 'C:\\Users\\<user_name>\\Downloads\\dnd_220116.csv'
    INTO TABLE `<database_name>`.`testing` CHARACTER SET 'utf8' 
    FIELDS ESCAPED BY '\\' 
    TERMINATED BY ',' 
    ENCLOSED BY '"' 
    LINES TERMINATED BY '\r\n' 
(`number`);