Home  >  Article  >  Database  >  MySQLLOADDATAINFILE解析_MySQL

MySQLLOADDATAINFILE解析_MySQL

WBOY
WBOYOriginal
2016-06-01 13:01:15807browse

LOAD DATA [LOW_PRIORITY] [LOCAL] INFILE'file_name.txt' [REPLACE | IGNORE]

INTO TABLE tbl_name
[FIELDS
[TERMINATED BY '\t']
[OPTIONALLY] ENCLOSED BY '']
[ESCAPED BY '\\' ]]
[LINES TERMINATED BY '\n']
[IGNORE number LINES]
[(col_name,...)]

自定义语法

FIELDS和LINES总的使用规则就是(在导入与导出的过程中by后面的符号一定要一致)
Load Data InFile 'C:/Data.txt' Into Table `TableTest` Fields Terminated By ','Enclosed By '"' Escaped By '"' Lines Terminated By '\r\n';

Fields Terminated By ',' Enclosed By '"' Escaped By '"'
表示每个字段用逗号分开,内容包含在双引号内

Lines Terminated By '\r\n';
表示每条数据用换行符分开

 

REPLACE和IGNORE关键词控制对现有的唯一键记录的重复的处理。如果你指定REPLACE,新行将代替有相同的唯一键值的现有行。如果你指定IGNORE,跳过有唯一键的现有行的重复行的输入。如果你不指定任何一个选项,当找到重复键键时,出现一个错误,并且文本文件的余下部分被忽略时

 

如果你不指定一个FIELDS子句,缺省值与如果你这样写的相同:

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

如果你不指定一个LINES子句,缺省值与如果你这样写的相同:

LINES TERMINATED BY '\n'

FIELDS和LINES总的使用规则就是(在导入与导出的过程中by后面的符号一定要一致)
换句话说,缺省值导致读取输入时,LOAD DATA INFILE表现如下:

在换行符处寻找行边界
在定位符处将行分进字段
不要期望字段由任何引号字符封装
将由“\”开头的定位符、换行符或“\”解释是字段值的部分字面字符.

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn