由制表符终止的 MySQL 字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2581961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:43:48  来源:igfitidea点击:

MySQL fields terminated by tab

mysqlload-data-infile

提问by Brian

I am trying to upload a tab delimitted file with MySQL. I want a query something likes this: LOAD DATA LOCAL INFILE 'file' INTO TABLE tbl FIELDS TERMINATED BY 'TAB'Is there something I can subsitute for TAB to make this work?

我正在尝试使用 MySQL 上传制表符分隔的文件。我想要一个类似这样的查询: LOAD DATA LOCAL INFILE 'file' INTO TABLE tbl FIELDS TERMINATED BY 'TAB'有什么我可以代替 TAB 来完成这项工作的吗?

回答by DRapp

have you tried '\t' the escape sequence + "T" is considered tab... haven't tried, but might be what you need

你试过 '\t' 转义序列 + "T" 被认为是制表符......没试过,但可能是你需要的

回答by Steve SZ

Just tried to find the answer to this question myself to save re-saving my file with commas separating instead of tabs...

只是试图自己找到这个问题的答案,以保存重新保存我的文件,用逗号分隔而不是制表符...

From an old MySQL reference manual, a long way down the page, you can find that TAB is the default separater for files loaded using LOAD DATA on MySQL.

从旧的 MySQL 参考手册中,在页面的很长一段位置,您会发现TAB 是在 MySQL 上使用 LOAD DATA 加载的文件的默认分隔符

See: http://dev.mysql.com/doc/refman/4.1/en/load-data.html

见:http: //dev.mysql.com/doc/refman/4.1/en/load-data.html

I just loaded a CSV file in this way into MySQL5.1.

我只是以这种方式将一个CSV文件加载到MySQL5.1中。

BW

体重

回答by Arun Solomon

fields terminated by '\t'

以“\t”结尾的字段

Try this one

试试这个

Note :

笔记 :

Field and Line Handling

场和线处理

For both the LOAD DATA and SELECT ... INTO OUTFILE statements, the syntax of the FIELDS and LINES clauses is the same. Both clauses are optional, but FIELDS must precede LINES if both are specified.

对于 LOAD DATA 和 SELECT ... INTO OUTFILE 语句,FIELDS 和 LINES 子句的语法是相同的。这两个子句都是可选的,但如果同时指定了 FIELDS,则 FIELDS 必须位于 LINES 之前。

If you specify a FIELDS clause, each of its subclauses (TERMINATED BY, [OPTIONALLY] ENCLOSED BY, and ESCAPED BY) is also optional, except that you must specify at least one of them. Arguments to these clauses are permitted to contain only ASCII characters.

如果指定 FIELDS 子句,则其每个子句(TERMINATED BY、[OPTIONALLY] ENCLOSED BY 和 ESCAPED BY)也是可选的,除非您必须至少指定其中之一。这些子句的参数只允许包含 ASCII 字符。

If you specify no FIELDS or LINES clause, the defaults are the same as if you had written this:

如果您未指定 FIELDS 或 LINES 子句,则默认值与您编写的内容相同:

FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\'

LINES TERMINATED BY '\n' STARTING BY ''

由 '\t' 终止的字段由 '' 包围,由 '\\' 转义

由 '\n' 终止的行由 '' 开始

Backslash is the MySQL escape character within strings in SQL statements. Thus, to specify a literal backslash, you must specify two backslashes for the value to be interpreted as a single backslash. The escape sequences '\t' and '\n' specify tab and newline characters, respectively.

反斜杠是 SQL 语句中字符串中的 MySQL 转义字符。因此,要指定文字反斜杠,您必须为要解释为单个反斜杠的值指定两个反斜杠。转义序列 '\t' 和 '\n' 分别指定制表符和换行符。

In other words, the defaults cause LOAD DATA to act as follows when reading input:

换句话说,默认值会导致 LOAD DATA 在读取输入时的行为如下:

Look for line boundaries at newlines.

在换行符处寻找行边界。

Do not skip any line prefix.

不要跳过任何行前缀。

Break lines into fields at tabs.

在选项卡处将行分解为字段。

Do not expect fields to be enclosed within any quoting characters.

不要期望字段包含在任何引用字符中。

Interpret characters preceded by the escape character \ as escape sequences. For example, \t, \n, and \ signify tab, newline, and backslash, respectively. See the discussion of FIELDS ESCAPED BY later for the full list of escape sequences.

将转义字符 \ 前面的字符解释为转义序列。例如,\t、\n 和\ 分别表示制表符、换行符和反斜杠。有关转义序列的完整列表,请参阅稍后对 FIELDS ESCAPED BY 的讨论。

Conversely, the defaults cause SELECT ... INTO OUTFILE to act as follows when writing output:

相反,默认值会导致 SELECT ... INTO OUTFILE 在写入输出时执行如下操作:

Write tabs between fields.

在字段之间写选项卡。

Do not enclose fields within any quoting characters.

不要将字段括在任何引用字符中。

Use \ to escape instances of tab, newline, or \ that occur within field values.

使用 \ 转义出现在字段值中的制表符、换行符或 \ 的实例。

Write newlines at the ends of lines.

在行尾写换行符。

see: https://dev.mysql.com/doc/refman/8.0/en/load-data.html

见:https: //dev.mysql.com/doc/refman/8.0/en/load-data.html

for more details.

更多细节。