开发者

How would I convert .csv data to mysql? [duplicate]

This question already has answers here: Closed 11 years ago.
开发者_如何转开发

Possible Duplicate:

Tool for importing CSV files into MySQL database?

A guy at work gave me a .csv file with thousands of records in it. There's about 5 columns (out of 20) that I would love to get inserted into a mysql database.

Any idea how I might go about that?


Using LOAD DATA INFILE. The example in the docs for CSV is:

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
  FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  LINES TERMINATED BY '\r\n'
  IGNORE 1 LINES;

You should remove the IGNORE 1 LINES clause if there is no header row in the CSV data.

Also, note that the order of the data in the file should match the order of the columns in the table. If they do not, you will need to specify the order like this:

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
  (column1, column2, ...)
  FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  LINES TERMINATED BY '\r\n'
  IGNORE 1 LINES;


use the LOAD DATA or BULK INSERT command

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜