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

Posted 大饼酥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql备份还原,cmd命令支持带空格的路径相关的知识,希望对你有一定的参考价值。

备份代码如下:

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命令支持带空格的路径的主要内容,如果未能解决你的问题,请参考以下文章

mysql中备份和还原数据库的语句啥啊

mysql备份与还原

MySQL数据库篇之数据库的备份和还原

[知了堂学习笔记]_Java代码实现MySQL数据库的备份与还原

MySQL如何备份与还原

mysql备份与还原