I am trying to backup MySQL DB using ProcessBuilder in Java but, I get this error.
"!Cannot run program "C:\Program Files\MySQL\MySQL Server 5.5\bin": CreateProcess error=5, Access is denied".
Here is my Code.
public static String backupDb() {
String resp=null;
try {
System.out.println("Started........");
ProcessBuilder builder = new ProcessBuilder("C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin", "mysqldump -u root -pmypass mydb> c:\\backup\\mybackup.sql");
builder.redirectErrorStream(true);
Process p = builder.start();
} catch(Exception e) {
resp="!"+e.getMessage();
}
return resp;
}
Where could I be going wrong?
There are a few things you have to do for this to work:
>) won't work.C:\\foo\bar\foobar\backup.sqlbut one of theC:\\foo,C:\\foo\\bar,C:\\foo\\bar\\foobarfolders doesn't exist, you'll get an error" ", else you'll get awkward errors, such as :'C:\Program' is not recognized as an internal or external commandHere is a tested version including all the things above. I'm passing the filepath as a parameter, because it's more flexible this way.