Import Large CSV files to MySQL In a Minute
Best way to Import a CSV file to MySQL
I have written a php script which can help you import a CSV file with 2 million rows to Mysql in 60 seconds.
You can download the php file from my github page here
Few days back when i was working in my office i had to upload a large csv file to a MySQL database .The csv file had 2 million rows . Phpmyadmin , mysqlworkbecnh doesn't support upload of these large CSV files .The phpmyadmin site suggests a script called big dump which is very slow, found many scripts on the web which try to do a series of insert statements but they are very slow.
After some research found that best way to upload large csv files is to use MYSQL LOAD DATA Command which makes task very easy and fast .
LOAD DATA LOCAL INFILE filename
INTO TABLE table name
FIELDS TERMINATED by ’,’
LINES TERMINATED BY ’\n’
You can learn more about this command here .
To make the process easier i have written a php script which uses the above command to impost a csv file.This is how the Php page looks like.
1. Keep this php file and Your csv file in one folder
2. Create a table in your mysql database to which you want to import
3. Open the php file from your localhost server
4. Enter all the fields
5. click on upload button