LOAD DATA INFILE only 1 record inserted - mysql

I have a csv file that I'm trying to import via the command line. But only 1 row is being inserted.
They are comma separated values. I'm on a Mac using Excel Mac. I save as a csv file. How can I tell if the lines are terminated by \r or \n or both? Here is the code I used:
LOAD DATA LOCAL INFILE '/Users/eric/Documents/contacts_test.csv' INTO TABLE `contacts_tmp` FIELDS TERMINATED BY ',' ESCAPED BY '\\' LINES TERMINATED BY '\n' (clientid,contactid,title,fname,mname,lname,suffixname,salutation,occupation,employer,home_addr1,home_addr2,home_city,home_state,home_zip,home_county,primary_addr1,primary_addr2,primary_city,primary_state,primary_zip,primary_county,work_addr1,work_addr2,work_city,work_state,work_zip,work_county,email,phone_home,phone_mobile,phone_work,fax,phone_other,codes);
thanks

I would just recommend trying the same command with ... LINES TERMINATED BY '\r\n' ... and see if you have better luck.

Had the same issue, LINES TERMINATED BY '\r' did the job.

If in your file the line is terminated by the ,, then you should add LINES TERMINATED BY ',\r\n'.
This will solve your issue as it did with mine.

Mac text files usually end in \r but you can find this out by using a hex editor and seeing what the lines end with.

Just try removing LINES TERMINATED BY '\n' altogether from your query.
If you don't specify a delimiter, MySQL fill figure it out automatically.

Related

Can I LOAD DATA with ugly data that has escape characters and quotes?

I have two records for example like this
11,avec myName à EX,Ex,0,2021-06-25
22,"andone \"ttt\"",Ex,0,2021-06-25
I am trying to load this into a table with MySQL with load data, and every time I try it, the quotes get cut off, or the back spaces don't show up.
I need to know if this is even possible. Can those two records go into a table and look exactly like they are in the CSV file?
I am using MySQL and trying
LOAD DATA LOCAL INFILE 'example.csv' INTO TABLE example;
Use the ENCLOSED BY and ESCAPED BY options.
LOAD DATA LOCAL INFILE 'example.csv'
INTO TABLE example
FIELDS OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\';
LOAD DATA LOCAL INFILE 'example.csv' INTO TABLE example
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(col1, col2, col3.col4,col5);
In mysql 8 this will get you an error please read
https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-file-location
Windws uses LINES TERMINATED BY '\r\n'
if the file comes from a linux system use `LINES TERMINATED BY '\n'
it os hard to tell without seeing the file what parameters would help exactly so you should try some variants out`.
also a editor with hexfile capability helps in such cases to analyse the struicture

How do I deal with semicolon in a cell when the file I am uploading semicolon delimited?

I am using load data infile to upload a 2gig csv file into mysql and getting some warnings that indicate that some of the cells include a semicolon when the actual csv file I am uploading is semicolon separated.
I suppose that changing the delimiter from semicolon may be an option but I do not have control over the export I am working with. Not sure how to do this without a find replace which obviously wouldnt work as it would just replace the semicolon that needs to remain in the field it has been exported to.
Here is what I am using:
load data infile '/file/path/bigfile.csv'
into table table_name fields terminated by ';'
LINES TERMINATED BY '\r\n' ignore 1 lines
(Column1, Column2, Column3, ....);
I guess the ultimate question is can you use a regex as a delimter when using load data infile...having problems finding this answer.
You have to mention the fields separated by in LOAD DATA command as:
LOAD DATA LOCAL INFILE 'abc.csv' INTO TABLE abc
FIELDS TERMINATED BY **';'**
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
FIELDS TERMINATED BY ';' is the main part to edit in your case.
Also you might be change the delimiter from semicolon to something else..

mySQL COLUMNS TERMINATED BY DELETE Character?

I am trying to load large text files that are delimited by DEL. Using Coldfusion I can do chr(127), but that doesn't seem to work here
LOAD DATA LOCAL INFILE "C:\\inetpub\\vhosts\\mysite.com\\dataload.data"
INTO TABLE tbl_data
COLUMNS TERMINATED BY '\0x7F'
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
I have been searching and trying a number of things that look like they can be DEL characters. Does anyone have any suggestions for the COLUMNS TERMINATED BY line?
After a lot of searching, I found that my original statement was close. The answer is:
COLUMNS TERMINATED BY X'7F'

MySQL LINES TERMINATED BY

What are the potential choices for LINES TERMINATED BY in MySQL?
I have a CSV file that I am trying to upload and neither \r\n, \n, or \r work.
Try inspecting the file using a binary-displaying utility like od (http://swoolley.org/man.cgi/1/od). That will show you imediately how your lines are terminated.
I agree with brian.
Query which i used to work are as follows.
load data local infile 'test.csv'
into table test_field fields
terminated by ','
lines terminated by '\n'

Importing space-delimited data into MySQL

I have file in the following format:
`e00` `e01` `e02` `e03`
`e10` `e11` `e12` `e13
Trying to import the data with
LOAD DATA INFILE 'file' INTO TABLE 'foo' FIELDS TERMINATED BY ' ' ENCLOSED BY '`'
only seems to get the first 3 fields of each line. Is there a way to load the data without altering the file format?
Let's all jump in the way-back machine to answer a 5-year old question!
The fact that the last item is not being loaded is a big hint. According to the manual:
If LINES TERMINATED BY is an empty string and FIELDS TERMINATED BY is
nonempty, lines are also terminated with FIELDS TERMINATED BY.
So, it's looking for a trailing space at the end of the line.
You could add a space to the end of each line in your input file, or try LINES TERMINATED BY '\n'