当前位置:   article > 正文

Mysql---C#在cmd中使用mysqldump导出sql文件

c# mysqldump

一、概述

本文描述了在C#中利用mysqldump工具导出sql文件。

二、代码片段

CmdHelper类代码如下:

    public class CmdHelper
    {
        public static string RunCmd(string strPath, string strcmd)
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.WorkingDirectory = strPath;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
            p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
            p.StartInfo.CreateNoWindow = true;//不显示程序窗口

            p.Start();
            p.StandardInput.WriteLine(strcmd );
            p.StandardInput.WriteLine("exit");
            string output = p.StandardOutput.ReadToEnd();
            string myError = p.StandardError.ReadToEnd();
            p.WaitForExit();//等待程序执行完退出进程     
            p.Close();
            return myError;
        }
    }
string myDumpToolPath = @"C:\Program Files\MySQL\MySQL Server 5.5\bin";

string mySqlPath = myCurrentDirectory + "\\" + "SqlFile\\";
string myDumpCmd = $"mysqldump -uroot -p{myPwd} -B {myDbName} --add-drop-database>{mySqlPath}\\{mySqlFileName}";

myTask2 = new Task(() => { CmdHelper.RunCmd(myDumpToolPath, myDumpCmd); });

 

转载于:https://www.cnblogs.com/3xiaolonglong/p/9967547.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/711589
推荐阅读
相关标签
  

闽ICP备14008679号