从外部导入数据进MySQL

时间:2021-07-17 00:47:04

语法格式:

LOAD DATA LOCAL INFILE 'E://test.txt' 
INTO TABLE test_table 
FIELDS TERMINATED BY ' '
#ENCLOSED BY ""
LINES TERMINATED BY '\r\n'
#IGNORE 1 LINES;

注释:

FIELDS TERMINATED BY ' ':表示列(字段栏)按照空格' '来分割
ENCLOSED BY "":表示字段闭合标签,例如ENCLOSED BY """",则字段以双引号”“闭合,在双引号内部的字段分隔符都会被忽略
LINES TERMINATED BY "\r\n":表示行的结束标志。Windows 系统下每一行的结束标志是"\r\n",Linux系统应该是LINES TERMINATED BY "\n"或<LINES TERMINATED BY "\r"或可以直接省略。
IGNORE 1 LINES:忽略特定行数,CSV文件可以忽略掉第一行标题