如何在没有mysql本地安装的情况下将mysql db从远程备份到本地? [英] How to Backup mysql db from Remote to local without mysql local installation?

查看:128
本文介绍了如何在没有mysql本地安装的情况下将mysql db从远程备份到本地?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,我正在尝试将 mysql 备份从远程服务器备份到我的本地机器.当我在本地机器上安装了 mysql 客户端时,我能够这样做.但是当客户端没有本地mysql客户端安装时,就不行了...

Good Day, I am trying to take mysql backup from remote server to my local machine. I am able to do so, when i have mysql client installed on local machine. But when the client doesnt have local mysql client installation, it is not working ...

我一直使用jdbc连接来连接mysql服务器,我的代码片段如下:

I have been connecting to mysql server using the jdbc connection and my code snippet is as follows:

try{     
String cs = "jdbc:mysql://" + dbh + ":" + dbport + "/" + database + "?user=" + USER + "&password=" + PASS+"";
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = java.sql.DriverManager.getConnection(cs);
String executeCmd = "";
     if(connection!=null){
        executeCmd = "mysqldump -u "+USER+" -p"+PASS+" "+database+" -r "+path;   
        Process runtimeProcess =Runtime.getRuntime().exec(executeCmd);
        int processComplete = runtimeProcess.waitFor();
        if(processComplete == 0){
            System.out.println("Backup taken successfully");
        } else {
            System.out.println("Could not take mysql backup");
        }
    } else{
        System.out.println("connection not sucess");
    }
}catch (Exception e) {
            e.printStackTrace();
}

我认为这可能是 mysqldump PATH 的一些问题,所以我将此文件复制到客户端计算机,并在 executeCmd 中指定了 mysqldump 的绝对路径.这次备份文件是在指定路径中创建的,但它是空的 &processComplete 返回一个值 2.我的问题是,

I think this might be some problem with mysqldump PATH, so i copied this file to client machine, and specified absolute path to mysqldump in executeCmd. This time the backupfile is created in specified path, but its empty & processComplete returns a value 2. My Questions are,

  1. 我是否需要任何其他 mysql 文件来运行 mysqldump 命令?如果是这样,除了将这些命令复制到本地机器之外,如何做到这一点?
  2. 返回值为 2 的 waitFor() 是什么意思?

谢谢&问候

我莫

推荐答案

解决了!,我忘记指定 HostIP &使用 mysqldump 命令更改我的 executeCmd 参数如下:

Solved it!, I forget to specify the HostIP & port with the mysqldump command Changed my executeCmd parameter as following:

executeCmd = PathToMySqlDumpFile+"mysqldump -h "+HOSTIP+" -P "+PORT+" -u "+USER+" -p"+PASS+" "+database+" -r "+path; 

连同 mysqldump 文件路径.我们只需要 mysqldump 文件将备份从远程服务器备份到本地.无需安装mysql客户端.

along with the mysqldump file path. We only need the mysqldump file to take the backup from remote server to local. No need for mysql client installation.

这篇关于如何在没有mysql本地安装的情况下将mysql db从远程备份到本地?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆