Last active
November 10, 2017 14:11
-
-
Save yamamoto-works/0fc4d13e988056b0472d435cf9c2e0ca to your computer and use it in GitHub Desktop.
mysql の load data local infile でcsvファイルを読み込ませる時の注意 ref: http://qiita.com/tpyamamoto/items/0214decd4a50c843a23d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load data local infile 'text.csv' INTO table load_test FIELDS terminated by ',' enclosed by '"' escaped by '"'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql > desc load_test; | |
+-------+--------------+------+-----+---------+-------+ | |
| Field | Type | Null | Key | Default | Extra | | |
+-------+--------------+------+-----+---------+-------+ | |
| text1 | varchar(256) | YES | | NULL | | | |
| text2 | varchar(256) | YES | | NULL | | | |
| text3 | varchar(256) | YES | | NULL | | | |
+-------+--------------+------+-----+---------+-------+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hunk_1.csv | |
aaaaaa,bbb""bbbb,cccccccc | |
xxxxxx,yyy"yyyy",dddddddd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> load data local infile 'hunk_1.csv' INTO table load_test FIELDS terminated by ',' enclosed by '"' escaped by '"'; | |
Query OK, 2 rows affected (0.05 sec) | |
mysql> select * from load_test; | |
+-----------+--------------+--------+ | |
| text1 | text2 | text3 | | |
+-----------+--------------+--------+ | |
| aaaaaaaaa | bbb"bbbb | cccccc | | |
| xxxxxx | yyyyy"yyyyy" | zzzzzz | | |
+-----------+--------------+--------+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hunk_2.csv | |
aaaaaa,"bbbbbbb,cccccccc | |
xxxxxx,yyyy"yyy,dddddddd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> load data local infile 'hunk_2.csv' INTO table load_test FIELDS terminated by ',' enclosed by '"' escaped by '"'; | |
Query OK, 1 row affected, 1 warning (0.05 sec) | |
mysql> select * from load_test; | |
+----------------------------+---------------------------------------------+--------+ | |
| text1 | text2 | text3 | | |
+----------------------------+---------------------------------------------+--------+ | |
| aaaaaa | "bbbbbbb,cccccccc | |
xxxxxx,yyy"yyyy,dddddddd | |
| NULL | | |
+----------------------------+---------------------------------------------+--------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment