Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

If you want to import the content of a CSV file into a MySQL table then you can follow example below.


CSV file


id,name,surname,
1,inanzzz,hello,
2,welcome,home,

MySQL table


CREATE TABLE `my_imports` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`surname` varchar(45) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Import command


mysql> SELECT * FROM my_imports;
Empty set (0.00 sec)

mysql> LOAD DATA LOCAL INFILE '~/Desktop/Untitled.csv'
-> INTO TABLE `my_imports`
-> FIELDS TERMINATED BY ','
-> ENCLOSED BY '"'
-> LINES TERMINATED BY '\n'
-> (`id`, `name`, `surname`);

Query OK, 2 rows affected, 4 warnings (0.01 sec)
Records: 3 Deleted: 0 Skipped: 1 Warnings: 4

mysql> SELECT * FROM my_imports;
+----+---------+---------+
| id | name | surname |
+----+---------+---------+
| 1 | name | surname |
| 2 | welcome | home |
+----+---------+---------+
2 rows in set (0.00 sec)