我有一个看起来像这样的CSV,
candidate_id,show_on_site,first_name,surname,gender,DOB,showdob,Location,height,eyes,hair_colour,hair_length,accents,unions,training,url,visible,availability
,26,urban talent,Strawberry,Shortcake,Female,11 Jan 1942,FALSE,Manchester,5'2,Brown,Black,Mid-length,Native Lancashire,Equity,Urban Talent TV & Drama Workshops,Strawberry-Shortcake---5.4.06.jpg,Yes,Yes
,29,urban talent,Rainbow,Brite,Female,12 Oct 1970,FALSE,Manchester,5'7,Brown,Dark Brown,Long,"Native Manchester, others include - Cheshire, RP, Patois, Standard USA",Equity Member,"BA Acting Studies, Arden School of Theatre<br>Urban Talent TV & Drama Workshops",Rainbow Brite 1_1.jpg,Yes,Yes
,31,urban talent,Webbigail,Vanderquack,Female,4 Jun 1947,FALSE,Manchester,5'0,Hazel,Blonde,Mid-length,"Native Manchester, others include - Liverpool, Cockney, Birmingham, West Country, Standard Scottish, Standard Welch, S Irish",,Manchester School of Acting<br>3 Years at David Johnson Acting Workshops,Webbigail Vanderquack web 1.jpg,Yes,Yes
,33,urban talent,Smurfette,Smurf,Female,1 Jul 1979,FALSE,Manchester,5'2,Dark Brown,Dark Brown,Long,"Native Manchester, others include - Liverpool, RP, Lancashire, Birmingham, Cockney, Devon, Geordie, West Country, Glasgow, Edinburgh, South African, Standard & Southern US, Persian, Asian, Indian ~ good ear for accents",,"Manchester School of Acting, with Mark Hudson<br>North Cheshire Theatre College, with David Johnson<Oldham Theatre Workshop",Smurfette Smurf web 4.jpg,Yes,Yes
是否可以将此数据插入到我的数据库中的现有列中,我似乎可以将其作为新表插入,然后将其列为A,B,C,D,E等列。
答案 0 :(得分:39)
在phpMyAdmin中,单击该表,然后单击页面顶部的“导入”选项卡。
浏览并打开csv文件。保持字符集原样。取消选中部分导入,除非您有HUGE数据集(或慢速服务器)。选择文件后,格式应该已经选择了“CSV”,如果没有,则选择它(不使用LOAD DATA)。如果要在导入前清除整个表,请选中“将表数据替换为文件”。如果您认为CSV文件中有重复项,请选中“忽略重复行”。现在是重要的部分,将接下来的四个字段设置为这些值:
Fields terminated by: ,
Fields enclosed by: “
Fields escaped by: \
Lines terminated by: auto
目前这些匹配默认值除了“Fields by by”,默认为分号。
现在点击Go按钮,它应该会成功运行。
答案 1 :(得分:5)
答案 2 :(得分:4)
使用LOAD DATA INFILE
SQL语句可以导入CSV文件,但无法更新数据。但是,你可以使用一些技巧。
从CSC加载到此表
LOAD DATA LOCAL INFILE '/file.csv'
INTO TABLE temp_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, field2, field3);
更新加入表格的实际表格
UPDATE maintable
INNER JOIN temp_table A USING (field1)
SET maintable.field1 = temp_table.field1
答案 3 :(得分:1)
这是由于id(自动递增字段丢失)而发生的。如果您在文本编辑器中通过为ID字段添加逗号来编辑它,则将解决此问题。