如何在 Windows Vista 中将 mysqldump .sql 文件加载到 MySQL 数据库

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

How can I load a mysqldump .sql file to a MySQL database in Windows Vista

mysqlwindowsmysqldump

提问by Eric Wilson

I'm trying to move a MySQL database from a Linux machine to one running Windows Vista.

我正在尝试将 MySQL 数据库从 Linux 机器移到运行 Windows Vista 的机器上。

Using mysqldump, I've obtained a .sqlfile, which I have moved to the Windows machine. Whats next?

使用 mysqldump,我获得了一个.sql文件,我已经将它移到了 Windows 机器上。下一步是什么?

If I were moving to another Linux machine, one could do this sort of thing:

如果我要搬到另一台 Linux 机器上,人们可以做这样的事情:

mysql -u username -p databasename < dumpfile.sql

Does anyone know of an analogous invocation that works from the Windows command line? Or are there tools to accomplish this?

有谁知道从 Windows 命令行工作的类似调用?或者是否有工具可以实现这一点?

When I try this type of command from the Windows command line, I get:

当我从 Windows 命令行尝试这种类型的命令时,我得到:

'mysql' is not recognized as an internal or external command

I've also tried:

我也试过:

mysql>  source C:\Stuff\dumpfile.sql

That gave:

这给了:

Failed to open file 'C:\Stuff\dumpfile.sql', error: 2

采纳答案by Kibbee

This same type of command should work in windows as well as Linux. Have you tried running this command? What type of error messages are you getting.

这种相同类型的命令应该可以在 Windows 和 Linux 中使用。你试过运行这个命令吗?您收到什么类型的错误消息。

I just tested on my local machine with MySQL on Windows XP. The only reason I could see this not working, is that MySQL isn't on your path. If it isn't in your path, you need to specify the whole path of the MYSQL executable, or run it from the directory it's stored in. You could also add the executable to the path if you plan to use the MySQL executable on a regular basis.

我刚刚在我的本地机器上用 Windows XP 上的 MySQL 进行了测试。我看到这不起作用的唯一原因是 MySQL 不在您的路径上。如果它不在您的路径中,您需要指定 MYSQL 可执行文件的整个路径,或者从它存储的目录中运行它。如果您计划在定期。

回答by jcsahnwaldt says GoFundMonica

See this comment by Jeff Zohrabon the MySQL documentation:

请参阅Jeff Zohrab对 MySQL 文档的评论:

For windows users, use forward slashes for the path delimiters. You also don't need to enclose the path to the file in quotes. E.g., the following works:

对于 Windows 用户,请使用正斜杠作为路径分隔符。您也不需要用引号将文件的路径括起来。例如,以下工作:

mysql> source C:/Documents and Settings/My name here/My Documents/script.sql;

Just in case, for Linux:

以防万一,对于 Linux:

mysql> source /path/to/script.sql;

回答by Alex Angelico

If you get an 'error 2' is because the comand is been executed, so it's not because MysQL is not been found.

如果你得到'错误 2' 是因为命令被执行了,所以不是因为没有找到 MySQL。

The error 2 is because you should use this path: 'C:/Stuff/dumpfile.sql'instead of 'C:\Stuff\dumpfile.sql'

错误 2 是因为您应该使用此路径:'C:/Stuff/dumpfile.sql'而不是'C:\Stuff\dumpfile.sql'

You could also try 'C:\\Stuff\\dumpfile.sql', but the unix like path it's the way to go.

你也可以尝试'C:\\Stuff\\dumpfile.sql',但是像 unix 这样的路径是要走的路。

But the easiest way is this:

但最简单的方法是这样的:

If the .sql file is in c:\temp, and the MySQL is installed in the default location:

如果 .sql 文件在 c:\temp 中,并且 MySQL 安装在默认位置:

C:\temp>"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe" -u root -p -h localhost myDatabase < myDatabaseDump.sql

Regards.

问候。

回答by Dana the Sane

If you don't mind doing it interactively, you can use the sourcecommand in the mysql shell, followed by the file name. Otherwise, I believe that Kibbee is right about pipes working in cmd.exe.

如果您不介意以交互方式进行,则可以source在 mysql shell 中使用该命令,后跟文件名。否则,我相信 Kibbee 关于在cmd.exe.

回答by blomman9

You can add an environment variable in Windows XP, tested and confirmed for Vista, through setx.exe, to the folder containing mysql.exe, mysqldump.exe etc. (This example relies on having MySQL Workbench installed and just modify the path to your choise.

您可以在 Windows XP 中添加一个环境变量,通过 setx.exe 对 Vista 进行测试和确认,添加到包含 mysql.exe、mysqldump.exe 等的文件夹中(此示例依赖于安装了 MySQL Workbench,只需将路径修改为您的选择。

setx path "%PATH%;C:\Program Files\MySQL\MySQL Workbench 5.2 CE"