zoukankan      html  css  js  c++  java
  • Mysql---C#在cmd中使用mysqldump导出sql文件

    一、概述

    本文描述了在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 FilesMySQLMySQL Server 5.5in";
    
    string mySqlPath = myCurrentDirectory + "\" + "SqlFile\";
    string myDumpCmd = $"mysqldump -uroot -p{myPwd} -B {myDbName} --add-drop-database>{mySqlPath}\{mySqlFileName}";
    
    myTask2 = new Task(() => { CmdHelper.RunCmd(myDumpToolPath, myDumpCmd); });
  • 相关阅读:
    前端常见跨域解决方案
    VS单元测试--初级篇
    高等数学思路
    二元函数求极值判别式AC-B^2
    向量积详解
    伯努利分布均值和方差
    两个标准正态随机变量相乘的方差
    a分位数与双侧a分位数
    中心极限定理概念理解与记忆
    样本方差概念解析
  • 原文地址:https://www.cnblogs.com/3xiaolonglong/p/9967547.html
Copyright © 2011-2022 走看看