1

I have created this table on MySQL :

create table Apolo(
Date date,
Name varchar(50)
);

I have imported an excel file :

LOAD DATA LOCAL INFILE 'C:/Users/File.csv'
INTO TABLE Apolo
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 10 ROWS
(@Date, Name);
set Date=str_to_date(@Date,'%d/%m/%Y');

and I get the error :

Error Code: 1193. Unknown system variable 'Date'

If I do not put this line :

set Date=str_to_date(@Date,'%d/%m/%Y');

I do not get the error but if I try to use :

select count(*) from Apolo where Date='03/09/2015';

it does not work. So the format is not recognisable.

2
  • is your data imported successfully along with date? also i see you create a table name Apolo but when you run query select count(*) from Apolo_BBC here table name is change Apolo_BBC Commented Sep 30, 2015 at 9:42
  • @Noman I changed the table name for stackoverflow. In MySQL it is correct. The problem is not this one :( Commented Sep 30, 2015 at 10:05

3 Answers 3

1

The date to insert into mysql database should be in the format

YYYY-MM-DD

Example: 2015-02-18

So change the date in csv file to the above specified format and try ..

Sign up to request clarification or add additional context in comments.

Comments

0

Check your Date column values in database. By default date format in mysql database is Y-m-d

Do you have values in this format.

2 Comments

The date on the .csv file is shown as "03/09/2015".
You are right on this. But you need to change this to Y-m-d format before insert to database. If you dont want to change format before insert, make sure your date column in database table contain dates.
0

Take the semi-colon out of this line

(@Date, Name);

The set should be in the same command. Watch out for the fact that you have a field name that is a reserved word - you may need to escape it.

2 Comments

I did that. The date on the .csv file is shown as "03/09/2015". I deleted the semicolon and then proceeded with this query : select count(*) from Apolo where Date='03/09/2015'; but I get 0 as a result.
I don't know what your csv looks like, or what is in your table after you import the csv. So I can't really comment any further I'm afraid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.