微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

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

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

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

解决方法

在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,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,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,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,The <article> is used to contain a main article. What is the tag used to break it into sections?,<time>,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)

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

不能找到它。…请告知…

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。