Dino Geek, try to help you

How to import a CSV file into a MariaDB table?


To import a CSV file into a MariaDB table, we will use the LOAD DATA INFILE SQL command like the following:

1. First, make sure that you have a database and table created. If not, create it:
```
CREATE DATABASE test;
USE test;

CREATE TABLE test_table( id INT NOT NULL AUTO_INCREMENT, column1 VARCHAR, column2 VARCHAR, PRIMARY KEY (id)
);
```
1. Locate your CSV file. Your MariaDB service needs to be able to access this file.

1. Run the LOAD DATA INFILE command to import your CSV file:
```
LOAD DATA INFILE ‘/path/to/your/csv/file.csv’
INTO TABLE test_table
FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”‘
LINES TERMINATED BY ‘\n‘
IGNORE 1 ROWS
(column1,column2);
```
Please replace ‘/path/to/your/csv/file.csv’ with the path where your file is located in your system. In case your CSV file includes a header row, include IGNORE 1 ROWS statement to disregard that row. Also, replace column1, column2, etc., with the actual names of your columns in the order they appear in the CSV.

Please note that file must be on the server host, and you must have FILE privilege.

Refer to the MariaDB documentation for detailed information: https://mariadb.com/kb/en/load-data-infile/

Be careful with the LOAD DATA INFILE command because it can overwrite existing data in your table. Make sure to back up your data before running the command.

You can also try to import the CSV file via tools like PHPMyAdmin, HeidiSQL, or DBeaver which often are easier for non-technical people.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use