4

下面是我用来创建数据库的制表符分隔备份的代码。

mysqldump --user=**** --fields-enclosed-by=\" --lines-terminated-by="\n" --password=**** --host=localhost --tab=/path/to/folder ****

我不能去工作的是:

--lines-terminated-by="\n"

目前,如果我的 MySQL 数据库中有一个 TEXT 列,它会输出如下:

"1"    "A test post"    "This is an example of text on multiple lines.
\
As you can see this is how it places it in the txt file.
\
Blah blah blah"
"2"    "Another post"    "More text....."

这就是我想要达到的目标

"1"    "A test post"    "This is an example of text on multiple lines.\nAs you can see this is how it places it in the txt file.\nBlah blah blah"
"2"    "Another post"    "More text....."

根据文档--lines-terminated-by=...使用输出时支持--tab。但我似乎无法让它工作。

4

1 回答 1

3

您得到的输出SELECT ... INTO OUTFILE. 换行符以默认转义字符为前缀,即\. 该--lines-terminated-by选项指的是使用什么字符作为记录分隔符,而不是如何表示字段内的换行符。

无法直接使输出看起来像您想要的那样mysqldump,但您可以对文件进行后处理以获得所需的结果。例如,您可以使用以下方式过滤文件:

perl -pe 's/\\\n/\\n/'
于 2013-09-21T10:03:41.377 回答