Import CSV file using MariaDB CLI

sertxudev

Sergio Peris

Posted on October 17, 2024

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.

💖 💪 🙅 🚩
sertxudev
Sergio Peris

Posted on October 17, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Import CSV file using MariaDB CLI
tutorial Import CSV file using MariaDB CLI

October 17, 2024

Clear screen at MariaDB CLI
tutorial Clear screen at MariaDB CLI

October 16, 2024