码迷,mamicode.com
首页 > 数据库 > 详细

Mysql备份还原,cmd命令支持带空格的路径

时间:2016-06-02 17:49:23      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

备份代码如下:

logger.info(dbName + "开始备份!");
String cmd = "\"\" \""+dataBaseBS.getInstallPath() +"bin\\mysqldump\" -h localhost -uroot -p123456 " + dbName
    + " > \"" + uploadPath + dbName + ".sql\""; // 一定要加 -h,localhost(或是服务器IP地址) 
Process process = Runtime.getRuntime().exec("cmd /c start /b " + cmd);
InputStreamReader isr = new InputStreamReader(process.getErrorStream());
LineNumberReader input = new LineNumberReader(isr);
String line;
while ((line = input.readLine()) != null) {
}
logger.info(dbName + "备份成功!");

 

 还原代码如下:

logger.info(dbName + "开始还原!");
String cmd = "\"\" \""+dataBaseBS.getInstallPath() +"bin\\mysql\" -h localhost -uroot -p123456 " + dbName
   + " < \"" + uploadPath + dbName + ".sql\""; // 一定要加 -h,localhost(或是服务器IP地址)
Process process = Runtime.getRuntime().exec("cmd /c start /b " + cmd);
InputStreamReader isr = new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(isr);
String line;
while ((line = input.readLine()) != null) {
}
logger.info(dbName + "还原成功!");

 

Mysql备份还原,cmd命令支持带空格的路径

标签:

原文地址:http://www.cnblogs.com/Mr-kevin/p/5553651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!