1

I want to make a backup of my remote mysql database. I have viewed many examples, but I can not find the answer what I am doing wrong. I have mysql server on my computer with other name than my remote database, just want to create sql file in my computer to have a copy. My button action performed code is:

try {
            String cs = "jdbc:mysql://db4free.net:3306/DBNAME?user=DBUSER&password=DBPASSWORD";
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection connection = java.sql.DriverManager.getConnection(cs);
            String executeCmd = "";
            if (connection != null) {
                executeCmd = "mysqldump -hwww.db4free.net -u DBUSER -pDBPASSWORD DBNAME > backup.sql";
                Process runtimeProcess = Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", executeCmd });
                int processComplete = runtimeProcess.waitFor();
                if (processComplete == 0) {
                    JOptionPane.showMessageDialog(rootPane, "OK");
                } else {
                    JOptionPane.showMessageDialog(rootPane, "Didn't make a copy.");
                }
            } else {
                JOptionPane.showMessageDialog(rootPane, "Failed");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
1

1 Answer 1

0

The system cannot find the file specified

Try adding path to the file

            executeCmd = "/usr/bin/mysqldump -hwww.db4free.net -u DBUSER -pDBPASSWORD DBNAME > backup.sql";
Sign up to request clarification or add additional context in comments.

6 Comments

Nope, I get error - java.io.IOException: Cannot run program "/usr/bin/mysqldump": CreateProcess error=2, The system cannot find the file specified
Where is mysqldump on your machine? Is it installed?
No. Is there any possibility to just make a *.sql file and not putt it into my local mysql server?
You must have mysqldump on the machine where this code is running. The code starts mysqldump-program
OK, let's I have checked my work PC and I have a working DB for my other older projects, but it throws me error, that I have mentioned in upper posts. I have checked my pat (echo %PATH%) and there is no path to mysql/bin. I have added it to Path. I updated my programm code above so now it shows me OK. But i do not see any changes in my local db. Why? Does my local db has to have the same name as remote one?
|

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.