Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import big xls file into mysql database

I want to import big xlsx ( spreadsheet file ) into mysql database. I did it before by phpmyadmin , but this file is too big ( 205000 rows ).

so when I wanna do it by phpmyadmin,it has taken a long time and wasn't done.

what is best and fast way to import it to mysql database?

like image 460
Moein Hosseini Avatar asked Oct 27 '25 09:10

Moein Hosseini


1 Answers

You can do it using the LOAD DATA command in MySQL: http://blog.tjitjing.com/index.php/2008/02/import-excel-data-into-mysql-in-5-easy.html

Save your Excel data as a csv file (In Excel 2007 using Save As)
Check the saved file using a text editor such as Notepad to see what it actually looks like, i.e. what delimiter was used etc.
Start the MySQL Command Prompt (I usually do this from the MySQL Query Browser – Tools – MySQL Command Line Client to avoid having to enter username and password etc.)
Enter this command:
LOAD DATA LOCAL INFILE ‘C:\\temp\\yourfile.csv’ INTO TABLE database.table FIELDS TERMINATED BY ‘;’ ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘\r\n’ (field1, field2);
[Edit: Make sure to check your single quotes (') and double quotes (") if you copy and paste this code]
Done!
like image 193
Alan Delimon Avatar answered Oct 29 '25 00:10

Alan Delimon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!