问题描述
我正在从 mysql 数据库导出描述字段:
SELECT REPLACE(description,char(13),'\\n')
FROM table u INTO OUTFILE '/var/lib/mysql-files/u.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
然后在 nodejs 中我使用 csv-parse 处理文件(必须使用它来处理异步):
const parse = promisify(require('csv-parse'));
const records = await parse(fileContents,{ delimiter: ',',columns: true,skip_empty_lines: true,record_delimiter: "\n" });
这是一个示例文本:
Married,mad scientist and tennisman from Germany. I might not be able
to spell the word "ubuntu" without spellcheck software,but be sure I
know the meaning.
然而解析器弄错了,将其分成 3 个字段:
'"Married,mad scientist and tennisman from Germany. I might not be
able to spell the word \\"ubuntu\\" without spellcheck software','but be sure I know the meaning."','\\N'
第三个字段来自mysql,出于某种原因,文件以\N而不是\n结尾。 我可以通过 sed 以及行尾逗号将其删除,但如果我的查询可以避免这种情况,总是会感谢一些提示。
然而对于将正文分成 2 个字段,我感到很困惑。 我尝试删除解析中的分隔符参数,但同样的问题。我试过放松:真的,一样。
知道我做错了什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)