MySQL 加载数据错误(错误代码:2 - “没有这样的文件或目录”)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23232417/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:26:59  来源:igfitidea点击:

MySQL LOAD DATA Error (Errcode: 2 - "No such file or directory")

mysqlsqlbulkinsertload-data-infile

提问by Solace

I am trying to load data into a table of my MySQL database, and getting this error.

我试图将数据加载到我的 MySQL 数据库的表中,并收到此错误。

LOAD DATA LOCAL INFILE 'C:\Users\Myself\Desktop\Blah Blah\LOAD DATA\week.txt' 
INTO TABLE week;

Reference: this

参考:这个

The path is hundred percent correct, I copied it by pressing shift and clicking "copy path as" and checked it many times. So any tips on this will be much appreciated. . My research:Seeing thisanswer, I tried by changing C:\Usersto C:\\Users. It did not work for me.

路径百分百正确,我通过按shift键并单击“复制路径为”复制它并检查了很多次。因此,任何有关此的提示将不胜感激。. 我的研究:看到这个答案,我试图通过改变C:\UsersC:\\Users。它对我不起作用。

Secondly, is there a way to use some kind of a relative path (rather than an absolute path) here?

其次,有没有办法在这里使用某种相对路径(而不是绝对路径)?

采纳答案by FumblesWithCode

I don't know what version of MySQL you are using but a quick Google search found possible answers to both your questions. Below are excerpts from the MySQL 5.1 Reference Manual:

我不知道您使用的是哪个版本的 MySQL,但通过 Google 快速搜索可以找到您的两个问题的可能答案。以下是MySQL 5.1 参考手册的摘录:

The file name must be given as a literal string. On Windows, specify backslashes in path names as forward slashes or doubled backslashes

The LOCAL keyword affects where the file is expected to be found:

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.

文件名必须作为文字字符串给出。在 Windows 上,将路径名中的反斜杠指定为正斜杠或双反斜杠

LOCAL 关键字影响文件的预期位置:

如果指定了 LOCAL,则该文件由客户端主机上的客户端程序读取并发送到服务器。该文件可以作为完整路径名指定其确切位置。如果作为相对路径名给出,则该名称将相对于启动客户端程序的目录进行解释。

Regards.

问候。

回答by Mario Vandeersar

I spent 2 days on this and finally got my mistake, Just changing backslashes by forward ones, as one contributor previously said. And finally worked for me. so was:

我花了 2 天的时间来解决这个问题,终于弄错了,正如一位贡献者之前所说的那样,只是将反斜杠改为正斜杠。最后为我工作。也是:

LOAD DATA LOCAL INFILE 'C:/ProgramData/MySQL/MySQL Server 5.7/Data/menagerie/pet.txt' INTO TABLE pet;

I just can say thanks a lot.

我只能说非常感谢。

p.s. don't waste time on ytb...

ps不要在ytb上浪费时间...

回答by SushiGuy

If using MySQL Workbench on a local Windows PC to connect to a remote MySQL server,

如果在本地 Windows PC 上使用 MySQL Workbench 连接到远程 MySQL 服务器,

  1. Add the "LOCAL" keyword
  2. Add double backslashes "\\" to your folder path
  1. 添加“本地”关键字
  2. 在文件夹路径中添加双反斜杠“\\”

If text file's first row has column names add "IGNORE 1 LINES".

如果文本文件的第一行有列名,则添加“IGNORE 1 LINES”。

LOAD DATA LOCAL INFILE 'C:\MyTabDelimited.txt'
INTO TABLE my_table IGNORE 1 LINES;

回答by Gjermund Dahl

Simply replace backslash with slash in the path. This works for me (MySQL Workbench 6.3 on Win 10):

只需在路径中用斜杠替换反斜杠即可。这对我有用(Win 10 上的 MySQL Workbench 6.3):

LOAD DATA LOCAL INFILE 'C:/Users/Myself/Desktop/Blah Blah/LOAD DATA/week.txt' 
INTO TABLE week;

Ref. https://dev.mysql.com/doc/refman/5.5/en/loading-tables.html

参考 https://dev.mysql.com/doc/refman/5.5/en/loading-tables.html

回答by AkhilSharma26

Instead of using double backslash That slash is also worked for me too.

而不是使用双反斜杠那个斜杠也对我有用。

回答by Mohan S

Try moving the week.txt file to the desktop

尝试将 week.txt 文件移动到桌面

then execute in a terminal window:

然后在终端窗口中执行:

LOAD DATA LOCAL INFILE 'C:\Users\Myself\Desktop\week.txt' 
INTO TABLE week;

回答by Vishnuraj V

Try removing the word LOCALfrom your query.

尝试LOCAL从您的查询中删除该词。