Skip to content

Instantly share code, notes, and snippets.

@badah
Last active March 28, 2019 20:43
Show Gist options
  • Save badah/62f595c771e0fe3712a30a0e2585fd1e to your computer and use it in GitHub Desktop.
Save badah/62f595c771e0fe3712a30a0e2585fd1e to your computer and use it in GitHub Desktop.
MYSQL: import csv data into table
# Create table with same csv headers.
CREATE TABLE table_name ( id mediumint(9) NOT NULL, {..}, PRIMARY KEY (id) );
# Load csv into table.
LOAD DATA INFILE '{abspath}/my-data.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment