通過調用MySql的工具mysqldump來實現。
類Cmd來實現調用cmd命令,
要啟動的進程所在的目錄是說mysql自動的備份還原數據庫工具mysqldump和mysql所在目錄,當然,這個方法可以執行別的命令行工具。
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
public class Cmd
{
/// <summary>
/// 執行Cmd命令
/// </summary>
/// <param name="workingDirectory">要啟動的進程的目錄</param>
/// <param name="command">要執行的命令</param>
public static void StartCmd(String workingDirectory, String command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WorkingDirectory = workingDirectory;
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(command);
p.StandardInput.WriteLine("exit");
}
}
備份方法:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Configuration;
using MDRClient.DataAccess;
namespace MDRClient
{
public partial class DataBackup : Form
{
public DataBackup()
{
InitializeComponent();
}
private