Skip to content

Instantly share code, notes, and snippets.

@kirkbackus
Last active August 29, 2015 14:10
Show Gist options
  • Save kirkbackus/aca992cb197f8a704514 to your computer and use it in GitHub Desktop.
Save kirkbackus/aca992cb197f8a704514 to your computer and use it in GitHub Desktop.
Example on how to load a CSV into a MySQL table

#How to load a CSV into MySQL

This example uses the assumption that I have a table called verse whose schema is

describe verse;
+------------+---------------+------+-----+---------+-------+
| Field      | Type          | Null | Key | Default | Extra |
+------------+---------------+------+-----+---------+-------+
| book_id    | int(11)       | NO   | PRI | NULL    |       |
| chapter    | int(11)       | NO   | PRI | NULL    |       |
| verse      | int(11)       | NO   | PRI | NULL    |       |
| text       | varchar(1000) | NO   |     | NULL    |       |
+------------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
LOAD DATA LOCAL INFILE 'FILENAME.csv' INTO TABLE verse
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
(book, chapter, verse, text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment