c#+mysql+表备份_C# mysql 备份复原表

这篇博客介绍了如何使用C#语言结合MySQL进行数据库表的备份和恢复操作。作者提供了一段代码,当点击按钮时,通过执行dos命令调用mysqldump进行备份,并实现了在后台验证和提示用户操作结果的功能。
摘要由CSDN通过智能技术生成

protected void btnCommit_Click(object sender, EventArgs e) { if (GridViewDBBackupList.SelectedIndex == -1) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(/"没有选择要恢复的备份!/");", true); } else { DataTable dt = common.getDataTable("select * from prodoc_jc_dbbackuprestore where id=" + GridViewDBBackupList.SelectedDataKey["id"].ToString()); if (dt != null && dt.Rows.Count > 0) { string filePath = @"" + System.Configuration.ConfigurationManager.AppSettings["dbbackuppath"].ToString(); string fileName = dt.Rows[0]["fileName"].ToString(); if (File.Exists(filePath + "//" + fileName))//d:/dbbackup/db.sql")) { string str = common.CallExe(@"mysql -uroot -p" + System.Configuration.ConfigurationManager.AppSettings["mysqlrootpwd"].ToString() + " " + System.Configuration.ConfigurationManager.AppSettings["mysqldbname"].ToString() + "" + filePath + "//" + fileName);         if (str.Equals("OK"))         {             ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(/"备份成功!/");closeBackupList();", true);             string sql = string.Empty;             sql = "insert into prodoc_jc_dbbackuprestore(filePath,fileName,autoORmanu";             if (Session["userRealName"] != null)                 sql += ",createPerson";             sql += ")";             sql += " values('" + filePath + "','" + fileName + "',1";             if (Session["userRealName"] != null)                 sql += ",'" + Session["userRealName"] + "'";             sql += ")";             common.executeNoQuery(sql);

欢迎大家阅读《C# mysql 备份复原表》,跪求各位点评,by 搞代码

bindData();         }     }     #endregion     #region 功能:执行dos命令;参数:一个,要执行的dos命令;返回值:成功,OK;失败,错误信息     public string CallExe(string argm)     {         Process p = new Process();         ProcessStartInfo startInfo = new ProcessStartInfo();         startInfo.FileName = "cmd.exe"; //设定需要执行的命令

startInfo.Arguments = "/C " + argm; //  设定参数,其中的“/C”表示执行完命令后马上退出         startInfo.UseShellExecute = false; //不使用系统外壳程序启动         startInfo.RedirectStandardInput = false; //不重定向输入         startInfo.RedirectStandardOutput = true; //重定向输出         startInfo.CreateNoWindow = true; //不创建窗口         p.StartInfo = startInfo;

try         {             if (p.Start()) //开始进程             {                 //if (milliseconds == 0)                 p.WaitForExit(); //这里无限等待进程结束                 //else                 //p.WaitForExit(milliseconds); //这里等待进程结束,等待时间为指定的毫秒                            }         }         catch (Exception ex)         {             return ex.ToString();         }         finally         {             if (p != null)                 p.Close();         }         return "OK";     }     #endregion

mysqldump -uxxx -pxxx --ignore-table=database.table1 --ignore-table=database.table2 > backup.sql mysqldump -uxxx -pxxx table1 table2 … > backup.sql

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值