Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql load data infile can't get stat of file Errcode: 2

I have looked all over and found no solution, any help on this would be great.

Query:

LOAD DATA INFILE '/Users/name/Desktop/loadIntoDb/loadIntoDB.csv'  INTO TABLE `tba`.`tbl_name`  FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES ( field1, field2, field3 ) 

Error:

Can't get stat of '/Users/name/Desktop/loadIntoDb/loadIntoDB.csv' (Errcode:2) 

NOTE:

I'm running MySQL Query browser on OSX 10.6.4 connecting to MySQL 5.x

Things I've tried:

  • Drag-n-drop
  • Chmod 777
  • Put in a folder with 777 permissions as well as the file having 777 permissions
like image 918
Phill Pafford Avatar asked Aug 12 '10 19:08

Phill Pafford


People also ask

Can't get stat of Errcode 13 Permission denied MySQL?

If you get Errcode 13 (which means Permission denied ) when starting mysqld, this means that the privileges of the data directory or its contents do not permit server access. In this case, you change the permissions for the involved files and directories so that the server has the right to use them.

How do I enable local Infile in MySQL?

For the mysql client, local data loading capability is determined by the default compiled into the MySQL client library. To disable or enable it explicitly, use the --local-infile=0 or --local-infile[=1] option.

What is load data infile?

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. If the LOCAL keyword is specified, the file is read from the client host. If LOCAL is not specified, the file must be located on the server.


2 Answers

try to use LOAD DATA LOCAL INFILE instead of LOAD DATA INFILE

otherwise check if apparmor is active for your directory

like image 192
Pierre Avatar answered Sep 19 '22 08:09

Pierre


I had a similar problem. The resolution was a mildly ugly hack, but much easier to remember than apparmor workarounds provided that you can 'sudo'. First, I had to put the input file in the mysql sub-directory for the database I was using:

sudo cp myfile.txt /var/lib/mysql/mydatabasename 

This does a copy and leaves 'root' as the file owner. After getting into mysql and doing a USE mydatabasename, I was able to populate appropriate table using

LOAD DATA INFILE 'mytabdelimitedtextfile.txt' INTO TABLE mytablename; 
like image 39
user2788525 Avatar answered Sep 23 '22 08:09

user2788525