public bool BackUpDB(BackupInfo backupInfo) { //调用mysqldump备份mysql数据库的语句 string backupsql = string.Format("mysqldump --host={0} --port={1} --user={2} --password={3} --default-character-set=utf8 --column-statistics=0 --lock-tables --routines --force --quick ", "152.136.73.240", "1733", "Lsa", "llfllf"); //mysqldump的路径 string mysqldump = backupInfo.MysqldumpPath; //需要备份的数据库名称 string strDB = "db_LibraryManagement"; //备份数据库的路径 string strDBpath = backupInfo.BackupPath; //判断备份的数据库路径是否存在 if (!Directory.Exists(strDBpath)) { Directory.CreateDirectory(strDBpath); } //备份数据库 if (!string.IsNullOrEmpty(strDB)) { string filePath = strDBpath + @"\" + backupInfo.BackupTime.ToString("yyyyMMdd_HHmmss") + strDB + ".sql"; string cmd = backupsql + strDB + " > " + filePath; RunCmd r = new RunCmd(); string result = r.runCmd(mysqldump, cmd); return(true); } return(false); }
private void btn_Recovery_Click(object sender, EventArgs e) { string mysqldump = textBox_MysqlDumpPath.Text.ToString(); if (File.Exists(mysqldump + "//mysqldump.exe")) { //存在 OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { //调用mysqldump备份mysql数据库的语句 string backupsql = string.Format("mysql --host={0} --default-character-set=utf8 --port={1} --user={2} --password={3} ", "152.136.73.240", "1733", "Lsa", "llfllf"); //mysql的路径 //需要备份的数据库名称 string strDB = "db_backuptest"; string filePath = ofd.FileName; MessageBox.Show(filePath, "当前选择的路径"); string cmd = backupsql + strDB + " < \"" + filePath + "\""; RunCmd r = new RunCmd(); string result = r.runCmd(mysqldump, cmd); MessageBox.Show("数据库恢复成功!", "MySQL", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("mysqldump路径错误", "提示"); } }