public boolean restore(BackupDto dto) throws Exception {
OutputStream out = null;
BufferedReader br = null;
OutputStreamWriter writer = null;
try {
String fPath = dto.getPath();
Runtime rt = Runtime.getRuntime();
String rootPath = WebUtil.getMysqlRoot();
logger.debug("My SQL bin path:" + rootPath);
String s = "" + rootPath+"bin\\mysql.exe -uroot -p123 logistics";
Process child = rt.exec(s);
out = child.getOutputStream();// 控制台的输入信息作为输出流
String inStr;
StringBuffer sb = new StringBuffer("");
String outStr;
br = new BufferedReader(new InputStreamReader(
new FileInputStream(fPath), "utf8"));
while ((inStr = br.readLine()) != null) {
sb.append(inStr + "\r\n");
}
outStr = sb.toString();
writer = new OutputStreamWriter(out, "utf8");
writer.write(outStr);
writer.flush();
out.close();
br.close();
writer.close();
logger.info("restore successfully.");
} catch (Exception e) {
logger.error(e);
return false;
} finally {
out.close();
br.close();
writer.close();
}
return true;
}
java还原mysql
最新推荐文章于 2021-03-16 13:20:17 发布