Why do I get an error when using LOAD DATA INFILE?

djq picture djq · Jun 1, 2011 · Viewed 8.9k times · Source

I'm trying to use SQL to upload a csv file from my laptop to a database, however I get a strange error. The code I am typing into the SQL window in phpMyAdmin is as follows:

LOAD DATA INFILE '/Users/myMac/testServerUpload.csv' 
INTO TABLE `testDatabase` 
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'

But I get the following error:

Error

SQL query:

LOAD DATA INFILE '/Users/myMac/testServerUpload.csv' INTO TABLE `testDatabase` FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'

MySQL said: Documentation
#1045 - Access denied for user 'ukld'@'%' (using password: YES) 

Should I be using LOAD DATA LOCAL INFILE instead of my current command as the file is on my computer? Both give me an error, and I thought LOCAL might mean that it is on the server. I could not find relevant advice searching for this error.

Answer

Ivana picture Ivana · Oct 31, 2011

I had this same issue and fixed it by using LOCAL and giving the full file path:

'C:/directory/file.csv' 

It seems the 1045 error comes from not having access to files on the server, which is where mySQL looks for the file if LOCAL is not specified.

See also: