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); });
  • 相关阅读:
    MySQL高可用之MHA的搭建
    MySQL MGR 集群搭建(单主模式&多主模式)
    ansible-playbook定义变量与使用
    linux LVM逻辑卷管理
    Oracle 19C RAC 静默(silent)安装on RHEL7.x
    Python语言基础02-变量和运算
    Python之路,Day6
    Python 之路 Day5
    Python之路,Day4
    Python之路,Day3
  • 原文地址:https://www.cnblogs.com/3xiaolonglong/p/9967547.html
Copyright © 2011-2022 走看看