[英]mysqldump returns code 6 when run from java, but the same command works fine from command line
When I run the same command from Java via Runtime.getRuntime I get the return code 6. The same command works fine from command line: 当我通过Runtime.getRuntime从Java运行相同的命令时,我得到返回代码6.相同的命令在命令行中正常工作:
process = Runtime.getRuntime().exec(mysqldumpCommand);
int processComplete = process.waitFor();
For those 2 commands I get the return code 6 when run from java and no dump. 对于这两个命令,当从java运行并且没有转储时,我得到返回代码6。 The work fine from command line(I don't have a password on the local env.) 从命令行工作正常(我在本地环境上没有密码)
mysqldump --user=root --password= --host=localhost dbname > c:\temp\dumpfile.sql
mysqldump --user=root --password="" --host=localhost dbname > c:\temp\dumpfile.sql
When deliberately put wrong password I get return code 2 in java, and a connection error in command line: 故意输入错误密码时,我会在java中返回代码2,并在命令行中出现连接错误:
mysqldump --user=root --password= --host=localhost dbname > c:\temp\dumpfile.sql
The return codes as I found them here : 我在这里找到的返回码:
Taken from client/mysqldump.c in MySQL 5.1.59:
#define EX_USAGE 1
#define EX_MYSQLERR 2
#define EX_CONSCHECK 3
#define EX_EOM 4
#define EX_EOF 5 /* ferror for output file was got */
#define EX_ILLEGAL_TABLE 6
How come I get (error) return code 6 when running the same command in java and works fine from command line? 为什么在java中运行相同的命令时得到(错误)返回代码6并在命令行中正常工作?
Later Edit: I try it from Windows. 稍后编辑:我从Windows尝试。
Runtime.exec
is not a shell , so redirections with > and < won't work. Runtime.exec
不是shell ,因此使用>和<的重定向将不起作用。 Currently the command is passing >
to mysqldump
, which interprets it as the name for the table you want to export. 目前该命令传递>
到mysqldump
,其解释为名称为要导出表。 (Hence return code 6, "illegal table".) (因此返回代码6,“非法表”。)
There are two solutions: 有两种解决方案:
Run a shell. 运行shell。 Use this command instead of the one you have: 使用此命令而不是您拥有的命令:
cmd.exe /c "mysqldump --user=root --password= --host=localhost dbname > c:\\temp\\dumpfile.sql"
Write the output from the command to a file yourself, with Process.getInputStream()
. 使用Process.getInputStream()
将命令的输出自己写入文件。
The mysqldump now supports --result-file=
mysqldump现在支持--result-file=
So it would look like this. 所以它看起来像这样。
mysqldump --user=root --password= --host=localhost dbname --result-file=c:\temp\dumpfile.sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.