CSV import omit a field - csv

I'm trying to import a table from CSV file to phpMyAdmin.
This is my table:
1 |Evan|Chigur |Male|1987-05-25|codefiscale0123|Via Calatafini 17, Palermo, 23451|user#user.it|marco_r|ee11cbb19052e40b07aac0ca060c23ee
22 |Hank|Zappasorca|Male|1987-05-25|codefiscale0123|Via Calatafini 17, Palermo, 23451|user#user.it|marco_r|ee11cbb19052e40b07aac0ca060c23ee
When i try to fill my table with this, the first field is omitted.
I've already checked out the correspondences of the fields between the cvs and mysql table.
Can anyone help me?
i use this query:
LOAD DATA LOCAL INFILE 'C:\\wamp\\tmp\\php7E3C.tmp' REPLACE INTO TABLE `bw_users`FIELDS TERMINATED BY '|'ENCLOSED BY '"'ESCAPED BY '\\'LINES TERMINATED BY '*'

how does this work for you?
LOAD DATA INFILE 'C:\\wamp\\tmp\\php7E3C.tmp' REPLACE INTO TABLE bw_users
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n'
for windows change to
LINES TERMINATED BY '\r\n'

Related

mysql load data infile it contain more data than there were input column

I'm a new to mysql, I try load csv file to mysql.
the csv like:
1,"a,b"
2,bc
3,d
the table like this:
create table test(ind varchar(10),var varchar(20));
when I load this csv file:
load data infile 'test.csv' into table test
fields terminated by ',' ;
I change this
the warning:
row 1 was truncated: it contained more data than there were input columns
I try this:
load data infile 'test.csv' into table test
fields terminated by ','
optionally enclosed by '"'
it doesn't work.
the common of "a,b" cause this error. but I don't know how to solve this question.
It sounds like maybe LOAD DATA isn't properly picking up on your line breaks. Try adding LINES TERMINATED BY ... to your call:
LOAD DATA INFILE 'test.csv' INTO TABLE test
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n' -- use '\n' if on Linux
(ind, var)
With the above call, MySQL should not view the comma inside the first quoted term "a,b" as being a field separator, but rather just part of the text of that column.

Import Big csv file into mySql

I am trying to import 300 mg csv file into mySql table. I am using this command:
LOAD DATA INFILE 'c:/csv/bigCSV.csv' IGNORE
INTO TABLE table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
And it works great with small files (1 mg and so on), but when I try to load a big file like the one mentioned, MySql Workbench (which I use to execute my queries) runs the command, everything ok and green but 0 rows affected. No changes at all in the table.
I am 10000% sure that the table is ok because when I take a portion of that file, eg 1mg and load it into the same table it works fine.
Did anyone had this kind of problems?
Thank you.
I have "solved" it. Don`t know why and I feel stupid for not playing with the statement earlier but like this:
LOAD DATA INFILE 'c:/csv/eventsbig.csv' IGNORE
INTO TABLE std9
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
Without the "IGNORE 1 LINES" at the end and it works with files of any size.
LOAD DATA LOW_PRIORITY LOCAL INFILE 'C:\\Learning\\App6_DBconnection\\CC.csv'
INTO TABLE `test`.`ccd`
CHARACTER SET armscii8
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n'
IGNORE 1 LINES (`Cd_Type`, `Full_Name`, `Billing_Date`);
This will work even for large data sets of more than 1.5 million records.

Load Data Local Infile SQL

I have an extract of data that is separated by using this character |
I need to load this data into a MySQL database table but I'm struggling with the lines terminated by function.
Can anyone please help me identify the correct method to terminate these fields? My example data is below.
I've already tried '"|"' but this doesn't work for the first and last fields.
Example:
00000000|OLD TRUCK|9|13|02|Z |Z |9999|111|99|ZZ|ZZ|ZZ|ZZ||ZZ|ZZ|99|999|2
Try something like this:
LOAD DATA LOCAL INFILE 'example.txt' INTO TABLE example_table
FIELDS TERMINATED BY '|'
LINES TERMINATED BY ',';
This worked for me
LOAD DATA LOCAL INFILE 'd:/test.csv' INTO TABLE test
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n';

How to import csv to mysql table?

Error: This query is just inserting the 1 line of file
LOAD DATA INFILE 'file.csv' INTO TABLE coords FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
And the file has 300k lines.
Columns are separeted by commas.
How is the coords created? Does it have 10 attributes for the data?
I just ran a quick test with a file containing six identical lines (using your data) and entered:
LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE coord FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
It read all 6 lines in.
I did this under Linux. If you're on Windows maybe you need '\r\n' (?).

Import CSV data into SQL database

I have a table with the following fields:
Name (varchar)
Ranking (int)
Age (int)
Favourite Court (varchar)
and a CSV file like this
name;age;current_ranking;favourite_court
sample1;22;5;Hard
sample2;21;6;Clay
I try to import it with MySQL using: LOAD DATA LOCAL INFILE 'c:/players.csv' INTO TABLE players FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'; or LOAD DATA LOCAL INFILE 'c:/players.csv' INTO TABLE players FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' (name,age,current_ranking,favourite_court);, with or without file header (that is name;age...).
It does not work, fields are messed up. Why?
You need to name the columns from your table, not the columns as headed in the file:
LOAD DATA LOCAL INFILE 'c:/players.csv' INTO TABLE players
FIELDS TERMINATED BY ';'
IGNORE 1 LINES
(Name, Age, Ranking, `Favourite Court`)
Also, as noted 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'