usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Diagnostics;usingSystem.Configuration;usingMDRClient.DataAccess;namespaceMDRClient

{public partial classDataBackup : Form

{publicDataBackup()

{

InitializeComponent();

}private voidbtnBackup_Click(objectsender, EventArgs e)

{try{//String command = "mysqldump --quick --host=localhost --default- character-set=gb2312 --lock-tables --verbose  --force --port=端口号 --user= 用户名 --password=密码 数据库名 -r 备份到的地址";//构建执行的命令StringBuilder sbcommand= newStringBuilder();

StringBuilder sbfileName= newStringBuilder();

sbfileName.AppendFormat("{0}", DateTime.Now.ToString()).Replace("-","").Replace(":","").Replace(" ","");

String fileName=sbfileName.ToString();

SaveFileDialog saveFileDialog= newSaveFileDialog();

saveFileDialog.AddExtension= false;

saveFileDialog.CheckFileExists= false;

saveFileDialog.CheckPathExists= false;

saveFileDialog.FileName=fileName;if(saveFileDialog.ShowDialog()==DialogResult.OK)

{

String directory=saveFileDialog.FileName;

sbcommand.AppendFormat("mysqldump --quick --host=localhost --default- character-set=gbk --lock-tables --verbose  --force --port=端口号 --user=用户 名 --password=密码 数据库名 -r \"{0}\"", directory);

String command=sbcommand.ToString();//获取mysqldump.exe所在路径String appDirecroty=System.Windows.Forms.Application.StartupPath+ "\\";

Cmd.StartCmd(appDirecroty, command);

MessageBox.Show(@"数据库已成功备份到" +directory+ "文件中","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}catch(Exception ex)

{

MessageBox.Show("数据库备份失败!");

}

}

}

}

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐