简体   繁体   中英

How can i import data from text file into MySQL

I have excel file, transformed into text file (file->save as), now i want to import this file into MySQL, i heard that the LOAD DATA INFILE could do this very quickly, however i don't know how to use it, should i write a php script in which i put the LOAD DATA INFILE syntax?

I guess your data is in CSV if you exported it from Excel? Then use LOAD DATA INFILE like this:

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

Explanation:

Fields terminated is your CSV seperator, enclosed by denotes that strings are enclosed with double quotes and line terminated by is the indicator for LOAD DATA INFILE to insert another row. The last line is to ignore the header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM