This is what I have:
List<String> restoreCmds = new ArrayList<>();
restoreCmds.add("mysql");
restoreCmds.add("-h" + host);
restoreCmds.add("-u" + login);
restoreCmds.add("-p" + pass);
restoreCmds.add("-e 'source dump.sql'");
restoreCmds.add(targetDB);
ProcessBuilder pb = new ProcessBuilder(restoreCmds);
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
Process pr = pb.start();
int exitVal = pr.waitFor()
I am getting the following error:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''source dump.sql'' at line 1
You don't need to add quote for source.
I changed the line to following and its working for me.
restoreCmds.add("-e source dump.sql");