使用Java环境从CMD行恢复MYSQL
我正在使用 Java 和 Mysql 作为程序,我正在使用脚本文件来恢复数据库。
在Java下我正在执行命令:在bin下:mysql -u root -proot test< c:\test.mysql
它没有运行,而如果我在命令行下运行它,它将正确执行并恢复数据库。
有谁知道.. 为什么会发生.. 这是什么问题,为什么我在Java环境下运行它无法运行。
确切的语法: 我正在使用 Process P= runtime.getRunTime().exec(FilePath)
其中 FilePath 变量具有值: mysql -u root -proot test< c:\test.mysql
我使用的是Windiws环境。 而如果我在 CmdLine 中运行 FilePath,它将给出完美的结果。
非常感谢或帮助。
I am using Java and Mysql for a Program, I am Using a Script File in order to restore a Databsae.
Under Java I am Executing a command:under bin: mysql -u root -proot test< c:\test.mysql
It is not running while If I run it under cmd line it will execute properly and restore the database.
Is anybody there who knows.. why it happens..
Whats the problem, why its not running if i run it under Java environment.
EXACT SYNTAX:
I m Using Process P= runtime.getRunTime().exec(FilePath)
where FilePath Variable is having value: mysql -u root -proot test< c:\test.mysql
I am Using Windiws environment. while if I run the FilePath in CmdLine, it will give the perfect reesult.
Highly thankful or help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有同样的问题!
实际上,我唯一可以做的工作(在 Windows 上,尚未测试其他平台)是使用批处理文件:
这里是代码:
I had the same problem!
Actually the only thing that I could make work (on Windows, havent tested other platforms) is using batch files:
here is the code:
我认为我们需要更多信息。 只要路径设置相同,如果从命令行运行,则应该从 Runtime.exec() 运行相同的路径。 您看到什么错误?
尝试在脚本中设置命令,以便您可以将路径和命令输出回显到文件中以便稍后查看。 在 UNIX 中,看起来像
你使用的是 Windows,所以我不知道如何以这种方式设置命令文件; 重要的是确保将 mysql 命令的错误输出发送到文件。
I think we need some more information. As long as the paths are set up the same, if it will run from the command line, it should run the same from Runtime.exec(). What errors do you see?
Try setting the commend up in a script so you can echo the paths and the command output to a file to look at later. In UNIX that would look like
It looks like you're using Windows, so I don't know how to set of the command file exactly this way; what's important is to make sure you're sending the error output of the mysql commend to the file.