mysql 加载数据 infile 无法获取文件的统计信息 Errcode: 2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3471474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql load data infile can't get stat of file Errcode: 2
提问by Phill Pafford
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
我在连接到 MySQL 5.x 的 OSX 10.6.4 上运行 MySQL 查询浏览器
Things I've tried:
我尝试过的事情:
- Drag-n-drop
- Chmod 777
- Put in a folder with 777 permissions as well as the file having 777 permissions
- 拖放
- 第 777 章
- 放入777权限的文件夹和777权限的文件
回答by Pierre
回答by user2788525
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:
我有一个类似的问题。该决议是一个稍微丑陋的黑客,但比 apparmor 解决方法更容易记住,前提是您可以“sudo”。首先,我必须将输入文件放在我正在使用的数据库的 mysql 子目录中:
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
这会复制一份文件并将“ root
”保留为文件所有者。进入 mysql 并执行 a 后USE mydatabasename
,我能够使用填充适当的表
LOAD DATA INFILE 'mytabdelimitedtextfile.txt' INTO TABLE mytablename;
回答by Zodzie
Using --local parameter will help with this.
使用 --local 参数将对此有所帮助。
Example: mysqlimport --local databasename file.txt -p
示例: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"
来源: http://dev.mysql.com/doc/refman/5.1/en/load-data.html “--local 选项导致 mysqlimport 从客户端主机读取数据文件”
回答by jciloa
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.
对我来说,将内容复制到 /tmp 并将其用作源文件夹就可以了。我使用 MariaDB,我的版本不允许使用“LOCAL”修饰符。有趣的是,授予对 CSV 文件夹的读写访问权限也不起作用。
回答by Akash Rudra
I had the same problem while populating a table in mysql on a AWS instance.
我在 AWS 实例上的 mysql 中填充表时遇到了同样的问题。
In my case i had the csv file in the instance itself.
就我而言,我在实例本身中有 csv 文件。
Putting the Absolute path solved my problem.
放置绝对路径解决了我的问题。
Here's the line from MySQL documentation
这是 MySQL 文档中的一行
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.
如果指定了 LOCAL,则该文件由客户端主机上的客户端程序读取并发送到服务器。该文件可以作为完整路径名指定其确切位置。如果作为相对路径名给出,则该名称将相对于启动客户端程序的目录进行解释。