1

I am trying to import write a script that imports a csv file and parses it into mysql, then imports it in the db, I came across this article,but it seems to be written for ms sql, does anyone know of a tutorial for doing this in mysql, or better still a libary or script that can do it ?. Thanks :-)

http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/

Iain Simpson
  • 441
  • 4
  • 13
  • 29
  • 2
    possible duplicate of [Import CSV file directly into MySQL](http://stackoverflow.com/questions/4143938/import-csv-file-directly-into-mysql) – Michael Berkowski Jan 08 '12 at 01:46
  • How is it a duplicate ?, he has written the script already and is asking something about it, I am asking if there are any libraries or scripts anyone knows of BEFORE I have started doing anything. – Iain Simpson Jan 08 '12 at 01:48
  • The answer is likely to be the same, I reckon – syneticon-dj Jan 08 '12 at 01:59
  • "Duplicate" here means a question covers the same ground or is answered elsewhere. You'll find 2 possible answers in the linked question. – Michael Berkowski Jan 08 '12 at 01:59

1 Answers1

3

Using the LOAD DATA INFILE SQL statement

Example :

LOAD DATA LOCAL INFILE '/importfile.csv'
INTO TABLE test_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, filed2, field3); 

If you are looking for script / library. I want to refer below link. here you can find :

PHP script to import csv data into mysql

This is a simple script that will allow you to import csv data into your database. This comes handy because you can simply edit the appropriate fields, upload it along with the csv file and call it from the web and it will do the rest.

It allows you to specify the delimiter in this csv file, whether it is a coma, a tab etc. It also allows you to chose the line separator, allows you to save the output to a file (known as a data sql dump).

It also permits you to include an empty field at the beginning of each row, which is usually an auto increment integer primary key.

This script is useful mainly if you don’t have phpmyadmin, or you don’t want the hassle of logging in and prefer a few clicks solution, or you simply are a command prompt guy. Just make sure the table is already created before trying to dump the data. Kindly post your comments if you got any bug report.