如何将数据从csv文件导出到mysql数据库?

时间:2013-03-14 05:57:35

标签: mysql csv export-to-csv

如何将数据从csv文件导出到mysql数据库? 是否有任何查询或其他方式?

2 个答案:

答案 0 :(得分:2)

我认为你的意思是IMPORT。,方法如下:

load data local infile 'yourCSVfilepath.csv' into table tableNameHERE
fields terminated by ','
optionally enclosed by '"'
lines terminated by '\r\n'

答案 1 :(得分:1)

要从Mysql将数据导出到csv,请使用此

SELECT *
INTO OUTFILE '/tmp/tablename.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM tablename

要将csv导入Mysql,请使用此

LOAD DATA INFILE 'c:/tablename.csv' INTO TABLE tablename