Question

I have an application that submits data to a MySQL database, which is read from a csv file. Sometimes it works just fine, but every now and then the LOAD DATA INFILE won't find the file from the directory I tell it to.

Here's what I got..

//making the damn query
string ctStr2 = "LOAD DATA INFILE 'C:/wamp/www/damnfile.csv' INTO TABLE " + tableName + " FIELDS TERMINATED BY ';' LINES TERMINATED BY '\r\n'";

// Runs the sql command.
MySqlConnection conn = new MySqlConnection(connection);
MySqlCommand command = conn.CreateCommand();
command.CommandText = ctStr;
conn.Open();
command.ExecuteNonQuery();

So that's pretty much it...sometimes it gets the work done, sometimes it yells the error "File 'C:/wamp/www/damnfile.csv' not found (Errcode:13)"

Does anyone have any idea why does this keeps happening? I am pretty sure the file path is okay.

Thanks!

Was it helpful?

Solution

According to an answer in another question, errcode 13 for HY000 indicates a permissions issue. Also, from a bug report, some responses reveal,

"For security reasons, when reading text files located on the server, the files must either reside in the database directory or be readable by all. Also, to use LOAD DATA INFILE on server files, you must have the FILE privilege. See Section 5.7.3, “Privileges Provided by MySQL”."

also,

I also struggled with this. Turns out you need the file and directory to be world-readable: chmod 755 . chmod 744 file.dat

So it seems that the permissions of the file may be inadequate when the import takes place, occasionally. Are you dumping to this file on some sort of schedule? If the file is being recreated, and your import runs before the permissions are changed, this could be the result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top