如何使用 java 将远程 MySQL 数据库转储到我的本地计算机?



我正在尝试从我的java程序执行数据库备份。该数据库位于我的树莓派上,我正在从笔记本电脑访问它。 每次尝试这样做都会导致以下错误,错误到底指的是什么文件,它是否在我的树莓派中,如果是,我如何找到它?

欢迎所有建议。

这是我的代码:

void backUpDatabase(){
ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
ses.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
Runtime.getRuntime().exec("mysqldump -h " + connURL +" -u <user> -p <password> <databaseName>"
+ "> <The/local/path/for/the/backup> ");
} catch (IOException ex) {
Logger.getLogger(LogInScreenController.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Run");
}
}, 0, 1, TimeUnit.HOURS);
}

错误信息:

java.io.IOException: Cannot run program "mysqldump": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at login.LogInScreenController$4.run(LogInScreenController.java:544)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at 

在笔记本电脑上安装mysql clients实用程序。安装完成后,执行您的 java 程序/类。

您应该在要从中进行备份的客户端系统上具有MySQL客户端。

更新:

当您必须执行带有参数的命令时,请使用此 exec API 而不是 exec Api。

最新更新