如何在Java中备份远程数据库phpMyAdmin?

时间:2014-04-09 00:05:34

标签: java phpmyadmin database-backups

如何通过Java备份在phpMyAdmin上运行的数据库?

由于

1 个答案:

答案 0 :(得分:0)

一种方法是在项目目录中使用mysqldump二进制文件(来自mysql安装文件),并将其命名为:

StringBuilder sb = new StringBuilder("cmd /c mysqldump -h").append(HOSTNAME).append(" -u");
sb.append(UNAME).append(" -p").append(PASSWD).append(" ").append(DB_NAME);
for (String s : tableList) {
    sb.append(" ").append(s);
}
sb.append(" > backup.sql");
try {
    File file = new File("etc/");
    Process pr = Runtime.getRuntime().exec(sb.toString(), null, file);
    pr.waitFor();
} catch (IOException | InterruptedException ex) {
}