开发者

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

开发者 https://www.devze.com 2023-01-11 02:58 出处:网络
I have looked all over and found no solution, any help on this would be great. Query: LOAD DATA INFILE \'/Us开发者_运维技巧ers/name/Desktop/loadIntoDb/loadIntoDB.csv\'

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

Query:

LOAD DATA INFILE '/Us开发者_运维技巧ers/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


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

otherwise check if apparmor is active for your directory


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;


Using --local parameter will help with this.

Example: mysqlimport --local databasename file.txt -p

source: http://dev.mysql.com/doc/refman/5.1/en/load-data.html "The --local option causes mysqlimport to read data files from the client host"


For me, copying the contents to /tmp and using that as the source folder did the trick. I use MariaDB, and my version does not allow using the "LOCAL" modifier. Interestingly, giving read-write access to the CSV folder did not work either.


I had the same problem while populating a table in mysql on a AWS instance.

In my case i had the csv file in the instance itself.

Putting the Absolute path solved my problem.

Here's the line from MySQL documentation

If LOCAL is specified, the file is read by the client program on the client host and sent to the server. The file can be given as a full path name to specify its exact location. If given as a relative path name, the name is interpreted relative to the directory in which the client program was started.

http://dev.mysql.com/doc/refman/5.7/en/load-data.html

0

精彩评论

暂无评论...
验证码 换一张
取 消