Tuesday, May 19, 2009

imports comma seperated file (csv) to mysql database

below show the simple query you want

LOAD DATA LOCAL INFILE 'C:\\test.csv'
INTO TABLE testing
FIELDS TERMINATED BY ','
ENCLOSED BY '"' LINES
TERMINATED BY '\\n';

Here 

 C:\\test.csv is the csv file path that you want to import in to mysql database

 testing is the table that imported data hold in

\\n is the line end char of the csv file this may change \\r\\n , etc ...

by default mysql allow to import less than 1MB file for import into mysql,but if you want large file imports into mysql then you should do some changes.This happen because it by default mysql has Max packet size = 1MB

using mysql-administrator GUI you can easily change this  value
In mysql-administrator GUI --> startup varables --> Advanced Networking tab --> data/memory size group box --> Max packet size = "
your_value"

http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html



No comments:

Post a Comment