开发者

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

开发者 https://www.devze.com 2023-03-26 15:44 出处:网络
This question already has answers here: Closed 11 years ago. 开发者_如何转开发Possible 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

精彩评论

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

关注公众号