I have a huge 23 GB CSV file I am trying to load, and I’ve found that instead of converting it to insert statements which takes a while, It’s possible to directly load to the DB.
So I tried the following syntax:
LOAD DATA LOCAL INFILE client_report.csv into table client_report fields terminated by ',' optionally enclosed by '"' lines terminated by 'rn' ignore 1 lines;
mysql> LOAD DATA LOCAL INFILE client_report.csv into table
client_report fields terminated by ‘,’ optionally enclosed by ‘"’ lines
terminated by ‘rn’ ignore 1 lines; ERROR 1064 (42000): You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near
‘client_report.csv into table client_report fields terminated
by ‘,’ opti’ at line 1
I am at a loss, I seem to be following documentation to the letter, and checked
sHOW GLOBAL VARIABLES LIKE 'local_infile';
its ON.
2
Answers
The final solution that worked best, is two steps:
split -l 10000000 file.csv
which will generate files likexaa xab, xac ...
Note that if you don't explicitly set the fields and ID=null, it will try to insert first column into the autogenerated ID column, shifting all content by 1 column leaving the last one empty.
Also note starting from file
xab
, you need to remove theignore 1 lines
part otherwise you'll skip the first row on each file.The only way I know how to do this is using python. This example uses sqlite, but the concept is the same.
It will murder your ram, but with an large enough pagefile you should be fine. It will also take some time (up to a few hours).