admin

使用LOAD DATA LOCAL INFILE在mysql中成功CSV导入后没有SQL查询结果

sql

在mysqldb中成功导入.csv文件的内容后,我遇到一个奇怪的问题。将csv文件中的数据成功导入到db表中,但是如果我在表上运行带有条件的任何SQL查询,则不会返回查询结果。我能够运行查询:

select * from mst_question

但如果指定了条件且满足条件,则不会返回任何结果

select * from mst_question where qtype='single'

该表具有行,其中列qtype包含条件文本“ single”,但不返回任何结果。

奇怪的是,如果我编辑表中的“ qtype”列内容并通过键入“ single”来替换测试“ single”,则该行将返回…… 对于我编辑的每一行!

我的.csv文件:

que_id,test_id,que_desc,ans1,ans2,ans3,ans4,true_ans,qtype
,11,In which year is the HTML specification supposed to be complete and finalized?,2012,2015,2020,2022,D,single
,11,Which of the following doctypes was introduced by HTML5?,<!doctype xhtml>,<!doctype html>,"<!doctype html PUBLIC ""-//W3C//DTD HTML 5.0 Transitional//EN"">","<!doctype html5 PUBLIC ""-//W3C//DTD HTML 5.0 Transitional//EN"">",B,single
,11,How do you stop crawlers from following links to sites you don't want to be associated with?,"<a href=""#"" rel=""nofollow""> ","<a href=""#"" rel=""dontgo""> ","<a href=""#"" rel=""nogo""> ","<a href=""#"" rel=""noassociation"">",A,single
,11,Which tag is used to define a section of the page that has content that is related but not critical to the main content in HTML5?,<article> ,<sidesection> ,<aside> ,<section> ,C,single
,11,The <article> is used to contain a main article. What is the tag used to break it into sections?,<article> ,<time> ,<aside> ,<section> ,D,single

我的LOAD DATA LOCAL INFILE语法:

LOAD DATA LOCAL INFILE 'quest.csv' INTO TABLE mst_question FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" IGNORE 1 LINES

执行LOAD DATA LOCAL INFILE后的输出:

(5 row(s)affected)
(0 ms taken)

我的SQL查询(给出结果):

select * from mst_question

结果

(5 row(s)returned)
(0 ms taken)

我的SQL查询条件简单(没有结果):

select * from mst_question where qtype='single'

结果 :

(0 row(s)returned)
(0 ms taken)

我究竟做错了什么 ????

不能找到它。…请告知…


阅读 224

收藏
2021-07-01

共1个答案

admin

我的猜测是您的文件具有Windows换行符:

...0,2022,D,single\r\n

您尚未指定该LINES TERMINATED BY '\r\n'子句,因此MySQL可能默认为Unix样式(\n),因此它实际上会导入single\r您的列中。

您可以使用来检查确切的列内容HEX()

2021-07-01