MySQL LOAD DATA IN FILE Not Inserting all the values - mysql

I have a text file in the following format, which contains about a million coupon codes.
93C9LF,PDF934,24YWJ4
93C9LF,PDF934,24YWJ4
93C9LF,PDF934,24YWJ4
Below is my query
LOAD DATA LOCAL INFILE /var/www/coupons.txt
INTO TABLE coupons
FIELDS TERMINATED BY '' ENCLOSED BY '' ESCAPED BY ''
LINES STARTING BY '' TERMINATED BY ','
(coupon);
When I execute this query only some are inserted into the database. I would like to know what I am doing wrong or what could be done to improve this query.

Hi Rezaq you can use this:
LOAD DATA LOCAL INFILE '/var/www/coupons.txt'
INTO TABLE coupons
FIELDS TERMINATED BY '\t'
ENCLOSED BY ','
LINES TERMINATED BY '\n'
(coupon);

Related

Is there a way to ignore header line when importing csv file for mysql? [duplicate]

I'm trying to Load a CSV file into my MySQL database,
But I would like to skip the first line.
I fact It contains the name of my columns and no interesting data.
Here is the query I'm using:
LOAD DATA LOCAL INFILE '/myfile.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
(column,column,column);
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;
(reference)
For those curious, IGNORE N LINES should be after the separator qualifiers:
LOAD DATA LOCAL INFILE '/myfile.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(column,column,column);
Try this:
IGNORE N LINES
LOAD DATA INFILE "/path/to/file.csv"
INTO TABLE MYTABLE
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

Load Data from EXCEL/ CSV to MYSQL using query?

I am trying to load data from Excel/ CSV file in MYSQL DB?
What is wrong with this code??
LOAD DATA INFILE "D:/MY_SQL_Practice/Sales_Data.csv" INTO TABLE sales_data
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
ignore 1 rows;
Like describe on mysql reference, https://dev.mysql.com/doc/refman/8.0/en/load-data.html
The example used only ' and never " on syntax :
LOAD DATA INFILE '/tmp/jokes.txt' INTO TABLE jokes
FIELDS TERMINATED BY ''
LINES TERMINATED BY '\n%%\n' (joke);
Can you try this syntax ? replace " by ':
LOAD DATA INFILE 'D:/MY_SQL_Practice/Sales_Data.csv' INTO TABLE sales_data
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
ignore 1 rows;

MySQL Load Data Query: Issue with Backslash ( \ )

I have I have a huge csv file with 149 column and 25K+ rows to upload this file in MySQL table I am using MySQL LOAD DATA Query
MY Query is:
LOAD DATA local INFILE '/Dir/file.csv' INTO TABLE my_table FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' IGNORE 1 LINES
My query is working fine, the problem comes when my file has any Backslash (\) characters, the column value get disturb and file cell value not inserting in correct columns. is there any fix for this issue.
Thanks
LOAD DATA local INFILE '/Dir/file.csv' INTO TABLE my_table FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\b' LINES TERMINATED BY '\n' IGNORE 1 LINES
Use '\b' as escape character instead of '\' in your query.

Not retriving the data from csv file to mysql

I wanted to import the csv file into the mysql. I am using this following code:
LOAD DATA local INFILE 'D:\20507.csv'
INTO TABLE rohit1
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
But it is not working; it shows only first column record?
Help me to out.
Try this :
LOAD DATA local INFILE 'D:/20507.csv' INTO TABLE rohit1 FIELDS TERMINATED
BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;

Importing csv into MySQL

I've got a csv file I made with a bunch of info, but I cant get it to import properly...
Ive got these values in info.csv: id firstname lastname address state gpa credits
following a video, I used this:
LOAD DATA LOCAL INFILE '/IT101/info.csv' INTO TABLE 'student' FIELDS TERMINATED BY ','
ENCLOSED BY '"' ESCAPED BY '\' LINES TERMINATED BY '\n';
I get back:
PAGER set to stdout
and the values aren't there. What am I doing wrong?
EDIT: By the way, I alaready have two rows in the table from using insert into, just doing it 30 more times seemed like a waste of time
You can try...
LOAD DATA INFILE '/IT101/info.csv'
INTO TABLE students
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;