Skip to content

Instantly share code, notes, and snippets.

@ebta
Last active November 11, 2021 07:13
Show Gist options
  • Save ebta/a6a310097aa23dbd040e77460b500f2c to your computer and use it in GitHub Desktop.
Save ebta/a6a310097aa23dbd040e77460b500f2c to your computer and use it in GitHub Desktop.
Load Data [local] infile Mysql import from csv

First, accesss mysql command line using user and password :

mysql -u user -p

Run from mysql> prompt

SET GLOBAL local_infile=1;
quit;

Run again mysql command line

mysql --local-infile=1 -u root -p

Then load your csv files like this

LOAD DATA LOCAL INFILE '/home/user/your-files.csv'
INTO TABLE score_esay
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 ROWS
(col1,col2,col3,col4);
LOAD DATA LOCAL INFILE '/home/user/your-files.csv'
INTO TABLE score_esay
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