How to import Large .CSV files into MySQL

preview_player
Показать описание
Importing a large .csv file into a MySQL database using xampp and load data infile.

Mysql import statement...

ALTER TABLE `[insert table name]` DISABLE KEYS;
LOAD DATA INFILE '[insert full path to your csv here]'
INTO TABLE
`[insert table name]`
CHARACTER SET UTF8
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
ALTER TABLE `[insert table name]` ENABLE KEYS;

PHP Script for counting lines in .csv file ...
Replace ⋖ and ⋗ with open and closing pointy (angle) brackets
⋖?php
$filename = '[insert full path to your csv here]';
$file = new \SplFileObject($filename, 'r');
$file-⋗seek(PHP_INT_MAX);
$total_lines = $file-⋗key() + 1;
unset($file);
$file = null;
echo '⋖h2⋗The File has '.number_format($total_lines).' Lines⋖/h2⋗';
?⋗
Рекомендации по теме
Комментарии
Автор

Bro bro bro bro, thank you so much men, you just saved my a lot of hours.😍. Thank you so much.🙏🏻🙏🏻

atulgupta-g
Автор

I am having error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''bikes_data' DISABLE KEYS' at line 1. Please help.

manavmokawat
Автор

Thanks for the video. I spent hours try to figure this out. With your video took less than 30 minutes to complete the task.

He-utww
Автор

getting
A new statement was found, but no delimiter between it and the previous one. (near "LOAD DATA" at position 43)

AS-tc
Автор

if you want to add auto increment key to id please add last row dont forgot !!

cenktasci
Автор

Thank you, it's working but importing 322k records out of 326k records. Any idea, what could be the reason?

gfxtutstips
Автор

error while uploading: LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile

clementmuhirwa
Автор

I created the table with Workbench. When I import the CVS file, it’s only bringing in 12 rows. It then indicates it’s finished successfully. Re import and it adds the same 12 rows again. Why would it stop after just 12 rows? Wondering if I have a permission problem somewhere?

peterpowers
Автор

When I try to create the table, the error "undefined" pops up. Does this have to do with the primary key or index? I have a lot of rows of data (330)

mbsmvp