0

我交替应用注释 1 和 2。但我没有使用在 cmd 中工作的 java.mysqldump 获得 myqldump 文件。我认为在 cmd 中输入 mysqldump 评论后会询问密码。请帮助我fast.thanks提前。

   String dumpCommand = "C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump" + " -u " + user + " -p" + " " + database + " > " + path;
    **//command 1**
    Runtime rt = Runtime.getRuntime();
    File test = new File(path);
    PrintStream ps;

    try {
    //    Process child = rt.exec("Cmd /c \"C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump\" -u root -p saxco > "+path);//command 2

        Process child = rt.exec(dumpCommand);
        ps = new PrintStream(test);
         InputStream in = child.getInputStream();
        int ch;
        while ((ch = in.read()) != -1) {
           ps.write(ch);
            System.out.write(ch);
        }
4

3 回答 3

0

如此所述,您可以像这样在命令中指定密码[...] -pPASSWORD [...]。请注意,选项标志和实际密码之间不能有空格。-p

请记住,以这种方式指定密码存在安全风险!

于 2013-07-16T10:58:57.573 回答
0

如果您不使用密码,也不要使用 -p 选项。

String dumpCommand = "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump" + " -u " + 用户 + 数据库 + " > " + 路径;

或者如果你有一个(没有间隙)

String dumpCommand = "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump" + " -u " + 用户 + " -p" + 密码 + " " + 数据库 + " > " + 路径;

于 2013-07-16T11:03:30.463 回答
0

尝试这个-

String cmd="mysqldump -u "+USER+" -p"+PASSWORD+"  "+database+" --routines -r"+PATH;

                 Runtime runtime = Runtime.getRuntime();
                 Process exec;

                 exec = runtime.exec(cmd);

                 int processComplete = exec.waitFor();
         if(processComplete == 0){
         System.out.println("Backup taken successfully in "+PATH+" on "+new Date());
         } else {
         System.out.println("Could not take mysql backup  :ERROR:");
         }
于 2013-07-16T11:12:42.837 回答