public void exportData(){
String dbName = "jdbc:mysql://localhost/gmao";
String dbUser = "root";
String dbPass = "";
String executeCmd="";
String path="C:\test.sql";
executeCmd = "C:\\wamp\\bin\\mysql\\mysql5.5.24\\bin\\mysqldump -u " + dbUser + " -p" + dbPass + " --add-drop-database -B " + dbName + " -r " + path;
try {
Process runtimeProcess =Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if(processComplete == 0){
System.out.println("Backup taken successfully");
} else {
System.out.println("Could not take mysql backup");
}
} catch (IOException | InterruptedException ex) {
Logger.getLogger(AdminFW.class.getName()).log(Level.SEVERE, null, ex);
}
}
答案 0 :(得分:0)
在屏幕截图中,我可以清楚地看到您的密码为空,这就是为什么会提示您输入密码的原因。设置密码:
String dbPass = "myUltraSecretDbPasword";
如果您为数据库设置密码,一切都将开始工作而不按enter
。但是,如果您确实需要这样做,您可以随时向该过程发送密钥。
process.getOutputStream().write(13); // sends 'enter' code to default input of process aka process console
但请记住“等待”一段时间,直到流程开始并提示输入密码。