MySQLã®LOAD DATA INFILEãç¨ã«ãã使ãã®ã§ã使ãæ¹ãã¡ã¢
ãã使ããã¤
LOAD DATA INFILE '/tmp/foo.csv' INTO TABLE foo FIELDS TERMINATED BY ',' IGNORE 1 LINES;
csvãèªã¿è¾¼ãã«ã¯FIELDS TERMINATED BY ','ãå¿ è¦
LOAD DATA INFILE
ã¯ãã¿ãåºåããããã©ã«ãã«ãªã£ã¦ããããããã«ã³ãåºåãã§ããcsvãèªã¿è¾¼ãã«ã¯FIELDS TERMINATED BY ','
ã§ã«ã³ãåºåãã§ããäºãæå®ãã¾ãã
1è¡ç®ã«ãã£ã¼ã«ãåãå ¥ãã¦ããã®ã§ããããç¡è¦ãã
IGNORE 1 LINES
ãä»ãããã¨ã§ãå
é 1è¡ãç¡è¦ãããã¨ãåºæ¥ã¾ããã¤ã³ãã¼ãç¨ã®csvãä½ãéããã£ã¼ã«ãåããªãã¨åããã«ããããäºå¾ã«ä¿®æ£ãã¦åå©ç¨ãããã¨ãèããã¨ãã¤ã³ãã¼ãããæã ãæ¶ãã®ãé¢åãããã®ã§ã
主ãã¼ã§ããidãå¿ è¦
ã¤ã³ãã¼ãããcsvã«ã¯ãå ¨ãã£ã¼ã«ããé çªã©ããã«è¼ã£ã¦ããå¿ è¦ãããã¾ããauto_incrementãããã主ãã¼ã¯ãããªãã¨æã£ã¦ãã1åç®ã«ä¸»ãã¼ãè¼ããªãã¨ã§ãããã ãæ°å¤ãæ¸ããã«ç©ºæ¬ã«ãã¦ããããauto_incrementã¯åãã®ã§ãé ç®ãç½®ãã¦ããã ã*1ã§ãã
ãªããcreated_atãupdated_atã®æ§ãªããã¼ãã«ã®æå¾ã«ãããã£ã¼ã«ãã«ããã¼ã¿ãå ¥ããªãã¦ãè¯ãã¨è¨ãå ´åãé ç®æ°ã足ããªãåã«ã¯åé¡ãªãã§ããå¤åwarningsã«ã¯ãªãã¨æãã¾ããã
warningsã確èªãã
SHOW warnings;
LOAD DATA INFILE
ã使ãã¨ãã»ã¼å¿
ãä½ãããã®warningsã¯åºã*2ã¨æãã¾ããã確èªãããã¨ããããã¾ããLOAD DATA INFILE
å®è¡ç´å¾ã«ã®ã¿ãããã§ç¢ºèªã§ãã¾ãã
ERROR 13 (HY000): Can't get stat of '/home/myuser/foo.csv' (Errcode: 13)
FILE権éãç¡ãã£ãããmysql -u root
ã§LOAD DATA INFILE
ãããã¨ãããããããªã¨ã©ã¼ã«ãªãã¾ãããmysqlã®rootã§ã¯ãå¥ã¦ã¼ã¶ã¼ã®ãã¼ã ãã£ã¬ã¯ããªã¯åç
§åºæ¥ãªãæ§ã§ãã/tmp/foo.csv ã¨ãã«ç§»åãããèªã¿è¾¼ãã¾ããã