java导出mysql备份
public String BackDBNow(HttpServletRequest request, String path, String username, String password) throws IOException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String filename=System.currentTimeMillis()+".sql";
if (username.equals("root") && password.equals("")) {
File file = new File(path);
boolean directory = file.isDirectory();
boolean exists = file.exists();
if (!directory || !exists) {
request.setAttribute("message", "请输入正确的路径");
} else {
String sql = "cmd /c D:/mysql/mysql-5.5.46-winx64/bin/mysqldump -h192.168.88.11 -u" + username + " -pPassw0rd! test > " + path + "/"+filename;
Runtime.getRuntime().exec(sql);
}
request.setAttribute("message", "操作完成");
return "redirect:BackDB?username=" + username + "&password=" + password + "&path=" + path;
} else {
request.setAttribute("message", "用户名密码错误");
}
return "redirect:BackDB?username=" + username + "&password=" + password + "&path=" + path;
}