0

I am using mysqldump like this:

Runtime.getRuntime().exec("mysqldump -u USERNAME -pPASSWORD DBNAME > /path/to/location/backup.sql");

in order to dump it into my local files, my java program is deployed using kubernetes. Here is my code:

 @RequestMapping(value = "/testDumping", method = {RequestMethod.POST, RequestMethod.GET})
public Object test(@RequestBody Map<String,Object> params) throws IOException {
    String runStatement = (String)params.get("runStatement");
    Runtime runtime = Runtime.getRuntime();
    Process exec = runtime.exec(runStatement);
    return exec;
}

And I finally got this exception "java.io.IOException: Cannot run program "mysqldump": error=2, No such file or directory". What is the problem here?

2
  • Hi, could you please also post the error log? Commented Jun 30, 2021 at 13:57
  • Hello I just completed the post. Commented Jun 30, 2021 at 14:00

1 Answer 1

1

The error message is telling you exactly what the problem is:

java.io.IOException: Cannot run program "mysqldump": error=2, No such file or directory

This means that the shell is unable to find the executable file for "mysqldump". Try giving the entire absolute path to mysqldump inside your command like i.e. (assuming linux-like system):

Runtime.getRuntime().exec("/usr/bin/mysqldump -u USERNAME -p PASSWORD DBNAME > /path/to/location/backup.sql");

Exact path on Linux can usually be found using command which mysqldump

You could as well add this path to you PATH environment variable and keep your command as is (not 100% sure of this one as I'm usually working on Windows and am far from a Linux expert).

Sign up to request clarification or add additional context in comments.

2 Comments

Hi I tried to add the absolute path into the command but I then got this error "mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect".
It means you've moved one step forward. Now it's a matter of configuring mysqldump with the right command line, in which I'm mostly unqualified... Sorry (you are now actually calling mysqldump, but the connection details are wrong. Check socket/host/port/user/password)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.