MySQL备份(JAVA)

时间:2014-04-08 02:51:14

标签: java mysql

我无法使用MYSQLDUMP备份数据库的原因是什么? 在我的localhost中,我可以备份数据库但是当我在托管中使用数据库时,似乎有问题。我的托管可能无法备份数据库吗?顺便说一句,即时通讯在我的数据库中使用cloudbees。在使用托管MySQL时,我100%确定更改了所有用户名,密码和数据库名称。实际上它会创建.sql文件,但它是空的。

String executeCmd = "C:/xampp/mysql/bin/mysqldump -u " + username
                    + " -p" + password + " somedbname" + " -r "
                    + "C:/tech-report-db/backup"
                    + c.getTimeInMillis() + c.getWeekYear() + ".sql";
            try {

                Process runtimeProcess;

                runtimeProcess = Runtime.getRuntime().exec(executeCmd);

                int processComplete = runtimeProcess.waitFor();

                if (processComplete == 0) {
                    System.out.println("Backup created successfully");
                } else {
                    System.out.println("Could not create the backup");
                }

它返回错误“无法创建备份”


1 个答案:

答案 0 :(得分:0)

我解决了这个问题。抱歉,问题不完整。我使用远程mysql所以我需要包含hostip和端口

之前:

String executeCmd = "C:/xampp/mysql/bin/mysqldump -u " + username
                    + " -p" + password + " somedbname" + " -r "
                    + "C:/tech-report-db/backup"
                    + c.getTimeInMillis() + c.getWeekYear() + ".sql";

现在:

String executeCmd = "C:/xampp/mysql/bin/mysqldump -P "+port+ " -h "+hostIP+ " -u " + username
                    + " -p" + password + " somedbname" + " -r "
                    + "C:/tech-report-db/backup"
                    + c.getTimeInMillis() + c.getWeekYear() + ".sql";