Thursday, February 27, 2014

Import csv or excel file into mysql.

Import data from csv file into mysql particular table no need to create a separate script for that.Via phpmyadmin you can able to import the csv by choosing 'CSV' file format. if you more data some time phpmyadmin may not work to solve this you can import it via commend line.


load data local infile 'your local csv file path need to import'  into table table_name  fields terminated by ','  enclosed by '"'  lines terminated by '\n'  (fields);

EX: load data local infile '/home/administrator/country.csv'  into table country  fields terminated by ','  enclosed by '"'  lines terminated by '\r\n'  (country_name, country_code, currency_symbol, currency_code, time_zone);

To import data from Excel , first export it as CSV file then remove the header from generated CSV file.You can import it in to MYSQL table by running the above query.

Note: Line terminate is optional and one thing lines terminated may be differ '\n' or '\r\n';




No comments:

Post a Comment