mysql load data 导出、导入 csv

1、用mysql导出时,如果文件目录没有权限,可以将文件导出到 mysql 库所在的服务器上的 /tmp/ 目录下(推荐)

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';
2、从csv文件导入数据,导入的时候,可以将要导入的文件先复制到 mysql 库所在的服务器上的 /tmp/ 目录下(推荐)。
要将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`);
说明:

FIELDS TERMINATED BY ---- 字段终止字符
OPTIONALLY ENCLOSED BY ---- 封套符,将字段值包围起来,比如常用的: "(英文双引号),详细使用可以参见本文的例子!!
LINES TERMINATED BY ---- 行终止符

你可能感兴趣的:(mysql,导出,导入,load,csv)