mysql:源错误 2?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14684063/
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: SOURCE error 2?
提问by Clueless Gorilla
When I tried to source for a particular .sql file, namely 'metropolises.sql'
that I created and saved previously from a database, the following error is displayed:
当我尝试获取特定 .sql 文件(即'metropolises.sql'
我之前从数据库创建并保存的文件)时,会显示以下错误:
Failed to open file 'metropolises.sql', error: 2
无法打开文件“metropolises.sql”,错误:2
Any idea what went wrong?
知道出了什么问题吗?
回答by Lightness Races in Orbit
Assuming you mean that you are trying to use the source
commandin order to execute SQL statements from a text file, the error number given appears to be passed through from the POSIX layer.
假设您的意思是尝试使用该source
命令从文本文件中执行 SQL 语句,那么给出的错误号似乎是从 POSIX 层传递过来的。
Therefore, using this resource, we can deduce that the error value of 2 means "no such file or directory".
因此,使用此资源,我们可以推断错误值 2 表示“没有这样的文件或目录”。
In short, you got the path wrong.
简而言之,你走错了路。
Try providing an absolute path, as it's not clear what the current working directorywill be in the context of your MySQL server. You may be assuming that it's the working directory of your shell, but it's not obvious that we should expect this to be true.
尝试提供一个绝对路径,因为目前尚不清楚MySQL 服务器上下文中的当前工作目录。您可能会假设它是您的 shell 的工作目录,但我们并不认为这是真的。
回答by chad
Just use the absolute pathof the file and then, instead of using backslashes, use forwardslashes.
只需使用文件的绝对路径,然后使用正斜杠代替反斜杠。
Example:
例子:
with backslashes: source C:\folder1\metropolises.sql
with forward slashes: source C:/folder1/metropolises.sql
带反斜杠:源 C:\folder1\metropolises.sql
带正斜杠:源 C:/folder1/metropolises.sql
回答by user1906580
Related issue I had getting error 2 running source command: filename must not be in quotes even if it contains spaces in name or path to file.
相关问题 我在运行源命令时遇到错误 2:即使文件名或文件路径中包含空格,文件名也不能用引号引起来。
回答by techieWannabe
It's probably the file path to your file. If you don't know the exact location of the file you want to use, try to find your file in Finder, then drag the file into Terminal window
这可能是您文件的文件路径。如果您不知道要使用的文件的确切位置,请尝试在 Finder 中找到您的文件,然后将文件拖入终端窗口
mysql> SOURCE dragfilePathHere
回答by user3030395
I first reach to the file
我首先到达文件
c:\windows>cd c:\akura\Db Scripts
c:\akura\Db Scripts>mysql -u root -p root
mysql>\. EXECUTER_NEW_USER.sql
here EXECUTER_NEW_USER.sql my file name
回答by Alex_Aleluia
I've had the same error on Windows. I solved it with (after on cmd: mysql -u root):
我在 Windows 上也遇到过同样的错误。我解决了(在 cmd 之后:mysql -u root):
mysql> SOURCE C:/users/xxx/xxxx/metropolises.sql;
Be sure you type the right file path
确保输入正确的文件路径
回答by Ibrahim Isa
If you are using vagrant ensure that the file is on the server and then use the path to the file. e.g if the file is stored in the public folder you will have
如果您使用 vagrant,请确保该文件在服务器上,然后使用该文件的路径。例如,如果文件存储在公共文件夹中,您将拥有
sql> source /var/www/public/xxx.sql
Where xxx is the name of the file
其中 xxx 是文件名
回答by LivePwndz
On my windows 8.1, and mysql 5.7.9 MySQL Community Server (GPL),
I had to remove the ;
after the file path.
在我的 Windows 8.1 和 mysql 5.7.9 MySQL Community Server (GPL) 上,我不得不删除;
文件路径之后的 。
This failed: source E:/jokoni/db/Banking/createTables.sql;
这失败了:来源 E:/jokoni/db/Banking/createTables.sql;
This Worked: source E:/jokoni/db/Banking/createTables.sql
(without termination, and forward slashes instead of windows' backslashes in path)
这有效:源E:/jokoni/db/Banking/createTables.sql
(没有终止,并在路径中使用正斜杠而不是windows的反斜杠)
回答by Lpgfmk
I got this error in mysql command line using this query:
我使用以下查询在 mysql 命令行中收到此错误:
source `db.sql`;
I changed the above to the following to make it work:
我将上述更改为以下内容以使其正常工作:
source db.sql;
回答by Andrew Rhyne
On my Mac, this is the only solution worked for me.
在我的 Mac 上,这是唯一对我有用的解决方案。
https://stackoverflow.com/a/45530305/5414448
https://stackoverflow.com/a/45530305/5414448
1 - Download the .sql file and remember it's location.
2 - Open your mysql from command prompt or terminal.
3 - Create a database with the same name as that of the database present in the .sql file (create database your_database_name)
4 - Now exit out from the mysql command line client
5 - Now try and execute this command =>
mysql -u your_username -p your_database_name < your_sql_file_with_complete_location
example - mysql -u root -p trial < /home/abc/Desktop/trial.sql
here my .sql file is named trial and is present in the desktop, the database is also name trial
6 - You should now have your sql file imported to the corresponding mysql database.