Importing csv into MySQL - 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;

Related

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;

MySQL LOAD DATA IN FILE Not Inserting all the values

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);

null values after csv import

Consider a table to store SSN and DOB.
CREATE TABLE fbi
(
ssn BIGINT,
dob DATE
)
Data was loaded into the table:
LOAD DATA LOCAL INFILE C:\test.csv
INTO TABLE fbi
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';
SELECT * FROM fbi;
It is showing null values for DOB. I don't understand the error.
"ssn","dob"
5,"1952-11-15"
6,"1973-12-23"
6,"1951-12-23"
1,"1962-03-21"
It most likely has to do with the date formatting in your csv file. MySQL likes dates in the format yyyy-mm-dd. e.g. 2010-10-09. You might be able to get more information by issuing the following command in the MySQL command console immediately after your import:
show warnings;
UPDATE:
I see that your date field is quoted. If you have a quoted date, you'll need to tell MySQL that by adding OPTIONALLY ENCLOSED BY '"' to your import command (see MySQL manual for LOAD DATA INFILE). Try this:
LOAD DATA LOCAL INFILE C:\test.csv
INTO TABLE fbi
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';
BTW: I hope those SSN's you've posted are fake or mangled in some unrecoverable way.