Mysql導入csv文件 MYSQL LOAD DATA INFILE命令可以把csv平面文件中的數據導入到數據庫中。 linux下:
LOAD DATA INFILE '/home/test/dump/ip_location.csv' INTO TABLE ip_location CHARACTER SET utf8 FIELDS TERMINATED BY ',' ENCLOSED BY '"'; --CHARACTER SET :mysql字符集,一定要加上,免去亂碼麻煩 --INTO TABLE :導入到哪個表 --FIELDS TERMINATED BY :以什麼作為分割符 -- ENCLOSED BY :被什麼包圍
windows:
LOAD DATA INFILE "d:/insert_data.csv" REPLACE INTO TABLE DEMO CHARACTER SET gb2312 FIELDS TERMINATED BY "," ENCLOSED BY "" LINES TERMINATED BY "\r\n"; --LINES TERMINATED BY:這個與linux不同,以什麼作為一行的結尾。