mysql import csv code example
Example 1: mysql load data infile csv
LOAD DATA LOCAL INFILE 'abc.csv' INTO TABLE abc
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(col1, col2, col3, col4, col5...);
Example 2: mysql load csv into table
LOAD DATA INFILE 'c:/tmp/discounts.csv'
INTO TABLE discounts
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Example 3: mysqlimport csv
C:\mysql\bin>mysqlimport
Connecting to localhost
Selecting database query
Loading data from LOCAL file: C:/mysql/bin/mysql-files/address.csv into address
query.address: Records: 3 Deleted: 0 Skipped: 0 Warnings: 0
Disconnecting from localhost
mysql> Select * from Address;
+
| Name | LastName | Address |
+
| Mohan | Sharma | Sundernagar |
| Saurabh | Arora | Chandigarh |
| Rajesh | Singh | Lucknow |
+
3 rows in set (0.00 sec)
Example 4: how to dump .csv file into mysql
LOAD DATA LOCAL INFILE 'c:/country.csv'
INTO TABLE country
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;