DEV Community

Cover image for Import CSV file using MariaDB CLI
Sergio Peris
Sergio Peris

Posted on • Originally published at sertxu.dev

Import CSV file using MariaDB CLI

If we have a CSV file, we can import the data to a database using the following command:

LOAD DATA INFILE '/home/sertxu/Desktop/users.csv'
INTO TABLE users
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Enter fullscreen mode Exit fullscreen mode

This command will get the file located at /home/sertxu/Desktop/users.csv and import its content into the table users ignoring the first line in the CSV file.

If your file doesn't contains the headers in the first row of the file, you can remove the IGNORE 1 ROWS from the command before executing it.

Top comments (0)