存储数据库备份

时间:2013-07-20 04:25:35

标签: java mysql

在特定的floder中执行但不存储数据库备份

public class NewClass {

    public static void main(String args[]) throws IOException, SQLException {

        String dbName = "test";
        String dbUser = "root";
        String dbPass = "root";
        try {
            String executeCmd = "";
            String[] comm = new String[4];
            comm[0] = "C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysqldump";
            comm[1] = "-u " + dbUser;
            comm[2] = "-p " + dbPass + " " + dbName;
            comm[3] = "-r backup.sql";
            Process runtimeProcess = Runtime.getRuntime().exec(comm);
            int processComplete = runtimeProcess.waitFor();
            if (processComplete == 0) {
                System.out.println("Backup taken successfully");
            } else {
                System.out.println("Could not take mysql backup");
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
}

我需要存储MySQL数据库备份,因此编码需要进行哪些更改

0 个答案:

没有答案