this is my csv file
player_id,match_id,player,champion_id,ss1,ss2,position
9,10,1,19,Flash,Smite,JUNGLE
10,10,2,267,Exhaust,Flash,DUO_SUPPORT
11,10,3,119,Heal,Flash,DUO_CARRY
12,10,4,114,Teleport,Flash,TOP
13,10,5,112,Flash,Exhaust,MID
14,10,6,72,Smite,Flash,JUNGLE
15,10,7,3,Flash,Teleport,TOP
I use:
LOAD DATA LOCAL INFILE '/home/downloads/participants.csv'
INTO TABLE participant
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
but the data are not loaded properly for example
the answer supposed to be 'JUNGLE' but instead only UNGLE
My theory is that this is a character encoding issue. This worked for me when I copy and pasted it into a new CSV.
It looks like it may have actually saved |ungle; not ungle.
To test this their, maybe open the CSV, delete the J and retype it manually.
Related
I have a Table in MySQL and I am adding data to it from a csv file
My code is:
LOAD DATA LOCAL INFILE 'C:/myaddress/file.csv'
INTO TABLE db.mytable
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
(`Currency`,`field2`,`field3`)
This loads fine except for the first row I add.
I'm adding a USD but when I do a query it imports it as USD.
This only happens for the first row. Anybody knows why this happens?
Solution:
This is an encoding issue, so to solve it, here are two options
1.- Encode the file differently
2.- Add a dummy line and use IGNORE 1 LINES
I think this is something related with your csv. It has been encoded with UTF-8 BOM in ISO-8859-1 (spanish?).
If you are using a editor like Notepad++ open your csv and select from the top menu -> Encoding -> utf-8 without DOM , save and try again.
I want to import an .xlsx file with ~60k rows to MySQL. Some columns contain Vietnamese characters. I managed to convert from .xlsx to .csv without messing up the character set. However I can't do the same when importing .csv to MySQL.
I used LOAD DATA INFILE. It looks something like this:
LOAD DATA LOCAL INFILE 'c:/Projekt/Big Data/events.csv'
INTO TABLE database.table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
(Source: http://blog.habrador.com/2013/01/how-to-import-large-csv-file-into-mysql.html)
This method imports the data fine but the character set of Vietnamese characters are totally messed up. I did change table's collation to utf8_unicode_ci.
I also test the traditional import method of MySQL with smaller datasets and it preserves the font perfectly. However I cannot use it since my file's size exceeds the limit of MySQL.
Really appreciate if someone could help me with this.
Try to explicit character set specify by import:
LOAD DATA LOCAL INFILE 'c:/Projekt/Big Data/events.csv'
INTO TABLE database.table
CHARACTER SET utf8
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
See docs for more details about loading from file.
this is my query for load data to mysql from csv. Here I have csv file in desktop and want to load data to my live server. This is possible to load in live server? Thanks in advance
LOAD DATA LOCAL
INFILE 'C:/Users/Home/Desktop/IPLOCATION.CSV'
INTO TABLE
`iplocation`
FIELDS TERMINATED BY ',';
I have used permutations on the following to load CSV data (with Windows line endings)
LOAD DATA LOCAL INFILE 'Country.csv' INTO TABLE `Country`
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
From this link
If LOCAL is specified, the file is read by the client program on the client host and sent to the server.
No it is not possible, your server wont resolve desktop client path
I have a csv file with four columns. Structure of this file is as shown below.
"Id","Title","Content","Author" "1","......","..............","..." "2",".............","....................","......"
The command below
LOAD DATA LOCAL INFILE '/data/trn.csv' INTO TABLE TR_DATA FIELDS TERMINATED BY ',' ENCLOSED BY '"' IGNORE 1 LINES ;
does not parse correctly and puts wrong inputs to fields. How can I parse correctly?
As documented under LOAD DATA INFILE Syntax:
Note
If you have generated the text file on a Windows system, you might have to use LINES TERMINATED BY '\r\n' to read the file properly, because Windows programs typically use two characters as a line terminator. Some programs, such as WordPad, might use \r as a line terminator when writing files. To read such files, use LINES TERMINATED BY '\r'.
So the structure of the csv file is like this:
Country,City,AccentCity,Region,Population,Latitude,
ad,aixas,Aixàs,06,,42.4833333,1.4666667
ad,aixirivali,Aixirivali,06,,42.4666667,1.5
ad,aixirivall,Aixirivall,06,,42.4666667,1.5
ad,aixirvall,Aixirvall,06,,42.4666667,1.5
The problem is that I don't know how to build the Load data query, I mean which separators to use and so on, mabe you guys can help me with an working example.
Does that help you?
load data local infile 'myfile.csv' into table myTable fields terminated by ','
lines terminated by '\n'
(Country,City,AccentCity,Region,Population,Latitude)