mysql导入数据load data infile用法整理

#基本语法:
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,   )]

terminated by分隔符:意思是以什么字符作为分隔符
enclosed by字段括起字符
escaped by转义字符

terminated by描述字段的分隔符,默认情况下是tab字符(\t)
enclosed by描述的是字段的括起字符。
escaped by描述的转义字符。默认的是反斜杠(backslash:\ )  

Mysql 导入导出csv

#用mysql导出时,如果文件目录没有权限,可以将文件导出到 mysql 库所在的服务器上的 /tmp/ 目录下(推荐<span></span>)
select * from s_reviews  where stars >0 limit 10 into outfile '/tmp/reviews.csv' fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\n';
#从csv文件导入数据,导入的时候<span></span><span></span>,可以将要导入的文件先复制到 mysql 库所在的服务器上的 /tmp/ 目录下(推荐<span></span>)。
要将csv文件的字段和mysql表中的字段对应起来,以免出错,同时也可以提醒自己导入的是哪些数据
>LOAD DATA LOCAL INFILE '/tmp/reviews.csv' INTO TABLE s_reviews fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\n' (`id`, `user_id`, `user_name`, `shop_id`, `shop_name`, `arv_price`, `environment`, `taste_or_product`, `service`, `comment_type`, `comment`, `stars`, `review_time`, `fetch_time`);

猜你喜欢

转载自blog.csdn.net/u013240609/article/details/81086277