linux+java+mysql环境,使用exec备份数据

linux+java+mysql环境,使用exec备份数据

    public void backupDB() throws IOException {
        String jdbcUser="root";
        String jdbcPassword="root";
        String dbHost="localhost";
        String dbName="myDatabase";
        Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", "/usr/bin/mysqldump -u" + jdbcUser + " -p" + jdbcPassword + " -h" + dbHost + " " + dbName + "> ~/Workspace/DatabaseBackup/"+dbName+"-`date '+%Y-%m-%d %H:%M:%S'`.sql"});
    }

结果如下图:
linux+java+mysql环境,使用exec备份数据_第1张图片

你可能感兴趣的:(JavaSE,mysql,linux)