简体   繁体   中英

Backup mysql from remote database with mysqldump process error

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();
        }

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM