Skip to content

Import CSV files into MySQL table

In this quick post, let’s see how to import data from csv formatted files into MySQL / MariaDB table. MySQL provides LOAD DATA LOCAL INFILE command to import data from filesystem into tables.

Syntax

LOAD DATA LOCAL INFILE  '<path to your file>'
INTO TABLE <table name> 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

if you have a header row in your csv, ignore 1 rows ignores the header while importing.

Example

OAD DATA LOCAL INFILE  '/home/anand/Documents/data/emp_master.csv'
INTO TABLE employee_master 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
See also  Update random values from a list into a column in MySQL

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.