LOAD DATA INFILE '/tmp/trains.csv' REPLACE INTO TABLE Trains FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\\\' LINES TERMINATED BY '\\\\r\\\
'IGNORE 1 LINES;
i get 0 rows inserted. ( Query took 0.0041 sec )
although the file does have data in there that i require to input.
also, i downloaded your csv, and it looks like this –
dateadded,From,Time
1372425854.78,"From West Kirby
Terminates","14:27a
On time"
1372425854.84,"West Kirby (circular route)
Starts here","14:36
On time"
looks like each row is spread across three lines of csv…
the problem there is the CSV file comes from scrapewiki so i would have to work out how to correct it via python before it’s told to import the data.
my project is a simple train time ticker using a raspberry pi and a 16x2 LCD that will show when the next train is from my local station.
if i import the file using phpmyadmin then it works fine but i need to work a way to automate it so that it can be told to run every few hours to download the new data.
Are you sure that the lines are terminated by carriage return line feed? I downloaded this and tested it on Linux and it worked (I did not have carriage return line feed '\r
’ but only line feed ’
’ as line separator):
mysql> LOAD DATA INFILE '/tmp/trains.csv' INTO TABLE Trains FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY "\\\\" LINES TERMINATED BY "\
" IGNORE 1 LINES;
Query OK, 2 rows affected (0.03 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from Trains;
+---------------+------------------------------------------+----------------+
| dateadded | from | times |
+---------------+------------------------------------------+----------------+
| 1372425854.78 | From West Kirby
Terminates | 14:27a
On time |
| 1372425854.84 | West Kirby (circular route)
Starts here | 14:36
On time |
+---------------+------------------------------------------+----------------+
2 rows in set (0.00 sec)