WinSCP Issue Grabbing MySQL Database

天大地大妈咪最大 提交于 2019-12-25 07:28:25

问题


I am trying to grab a MySQL database from a Linux box, and, with a little help from others, I have learned that the best way to grab the database is to do a mysqldump command. After looking at the Session.ExecuteCommand function, here is my code so far

static void Main(string[] args)
    {
        SessionOptions sessionSettings = new SessionOptions
        {
            Protocol = Protocol.SCP,
            HostName = "*****",
            UserName = "userName",
            Password = "password",
            SshHostKeyFingerprint = "ssh-rsa 2048 ******************"
        };

        using (Session session = new Session())
        {
            session.Open(sessionSettings);

            string strFilePath = @"/tmp/mySqlDatabases.gz";
            string strCommand = string.Format("mysqldump --opt -u {0} --password={1} --all-databases | gzip > {2}",
                              sessionSettings.UserName, sessionSettings.Password, tempFilePath);
            session.ExecuteCommand(strCommand).Check();
            session.GetFiles(strFilePath, @"C:\temp\mySqlDatabases.gz").Check();
        }
    }

When this runs, I am able to get the gz file with no issues, however I am not sure what I am suppose to do with the new file. When I extract it, I am given a 1 KB file that I have no clue how to use nor does it look like a database. Do I need to restore this dump file in order to get the database I want or is there another step to this that I am missing?

来源:https://stackoverflow.com/questions/39598774/winscp-issue-grabbing-mysql-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!