Pages

Tuesday, April 26, 2011

Import excel or csv sheet into mysql database

Please follow the following step to import in xslx file into database.

1. Open the excel sheet and save it as csv format (say you save the file as import.csv).
2. Open that file with notepad and check how the fileds are seprated, for example it may be seprated my ',' or ';' etc.
3. move that file into "C:\wamp\bin\mysql\mysql5.1.36\bin" directory.
4. open cmd and go to "C:\wamp\bin\mysql\mysql5.1.36\bin" directory.
5. create database and table in mysql.
(Suppose you created database "test" and table "test" and it have columns "sno" and "comment")
(Now you have to type this command to import into table).
6. LOAD DATA INFILE 'C:/wamp/bin/mysql/mysql5.1.36/bin/import.csv' into table test.test fields terminated by ',' lines terminated by '\r\n' (sno,comment);
7. Tada it's done :).

Reference : http://dev.mysql.com/doc/refman/5.0/en/load-data.html
http://blog.tjitjing.com/index.php/2008/02/import-excel-data-into-mysql-in-5-easy.html

No comments:

Post a Comment