MySQL 加载数据本地 infile 错误 2 文件未找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7623984/
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
load data local infile ERROR 2 file not found
提问by samuel
I've been ramming my face against this sql error for about 45 minutes, and I have a feeling it's going to be something silly.
大约 45 分钟以来,我一直在面对这个 sql 错误,我觉得这将是一件愚蠢的事情。
I'm trying to load a .txt file into my database, which is on a server elsewhere. I'm using putty on windows 7.
我正在尝试将 .txt 文件加载到我的数据库中,该数据库位于其他地方的服务器上。我在 Windows 7 上使用腻子。
The sql call I am using is the following:
LOAD DATA LOCAL INFILE "C:/Users/Sam/Desktop/students_data.txt" INTO TABLE students;
我正在使用的 sql 调用如下:
LOAD DATA LOCAL INFILE "C:/Users/Sam/Desktop/students_data.txt" INTO TABLE students;
The response I get is ERROR 2 (HYOOO): File 'C:/Users/Sam/Desktop/students_data.txt' not found (Errcode:2)
我得到的回应是 ERROR 2 (HYOOO): File 'C:/Users/Sam/Desktop/students_data.txt' not found (Errcode:2)
If anyone could shed some light on this that'd be extravagant. I already tried switching the /
to \
and using single quotes, etc., but nothing seems to work. The file path is copied by shift+clicking the actual file and pasting it.
如果有人能对此有所了解,那就太奢侈了。我已经尝试切换/
到\
并使用单引号等,但似乎没有任何效果。通过Shift+单击实际文件并粘贴来复制文件路径。
回答by prkarpi
I have found a solution. First delete the word LOCAL from the sql statement. Second - place your file into MySQL DATA folder usually - bin/mysql/msql5.5.8/data/and your DB with which you are working. It worked for me. You might want to check your MAX_FILE upload number in php.ini file if file is large.
我找到了解决办法。首先从sql语句中删除LOCAL这个词。其次 - 通常将您的文件放入 MySQL DATA 文件夹中 - bin/mysql/msql5.5.8/data/ 和您正在使用的数据库。它对我有用。如果文件很大,您可能需要在 php.ini 文件中检查您的 MAX_FILE 上传数量。
回答by ashga
Removing the word LOCAL
seemed to work for me; try it out!
删除这个词LOCAL
似乎对我有用。试试看!
回答by Cragmonkey
I had this problem too, then I read this:
我也有这个问题,然后我读了这个:
The file name must be given as a literal string. On Windows, specify backslashes in path names as forward slashes or doubled backslashes
文件名必须作为文字字符串给出。在 Windows 上,将路径名中的反斜杠指定为正斜杠或双反斜杠
(from http://dev.mysql.com/doc/refman/5.1/en/load-data.html)
(来自http://dev.mysql.com/doc/refman/5.1/en/load-data.html)
I diduse the LOCAL keyword, but escaped the file path like this: str_replace('\\','/',$file)
, then it worked like a charm!
我确实使用了 LOCAL 关键字,但是像这样转义了文件路径:str_replace('\\','/',$file)
,然后它就像一个魅力!
回答by Parallax
Had this too and solved it by using cmd.exe and found that the filename was mistakenly in the form filename.txt.txt and fixed it.
也有这个问题,用cmd.exe解决了,发现文件名错误的格式为filename.txt.txt,修复了。
回答by Bal Raj Sharma
Try to type path as C:\\mydir\\myfile.csv
i.e. use \\
instead of \
尝试输入路径为C:\\mydir\\myfile.csv
ie use\\
而不是\
回答by Nijhum Reza
just replace "\" by "/" as the path directory before the filename.txt in (""). it will be better if u just keep the file in mysql data folder and do the thing i mentioned above.it will definitely work.
只需将“\”替换为“/”作为(“”)中filename.txt之前的路径目录。如果你只是将文件保存在 mysql 数据文件夹中并做我上面提到的事情会更好。它肯定会工作。
回答by luckyfox
Sorry my previous answer is wrong.
对不起,我之前的答案是错误的。
In my case, I connect to a proxy, not the real physical mysql instance, so of course it could not get my local file.
就我而言,我连接到代理,而不是真正的物理 mysql 实例,因此当然无法获取我的本地文件。
To solve this, figure out the true physical mysql instance IP, connect it directly. You need help from the DBA.
要解决这个问题,找出真正的mysql物理实例IP,直接连接。您需要 DBA 的帮助。