Import CSV file using MariaDB CLI

Published at 17 Oct 2024

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;

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.