如何使用c#.net进行MySQL数据库的备份和还原 [英] How to take backup and restore of a MySQL DataBase using c#.net
本文介绍了如何使用c#.net进行MySQL数据库的备份和还原的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨........
我正在做一个Windows应用程序,因为我使用MySQL作为后端.我想通过在c#.net中编写代码来备份数据库.如果有人知道,请将该代码发送给我.我用谷歌搜索,但没有用.我找到了一个代码,但是它仅用于第一张表.我要整个数据库.
这是我使用的代码...
Hi........
I am doing a windows application in that i used MySQL as back end.I want to take the backup of Database by writing code in c#.net. If any body knows please send me that code. I googled but no use. I found one code but but its coming for 1st table only. I wan the whole Database.
This is the code which i used...
try
{
DateTime backupTime = DateTime.Now;
int year = backupTime.Year;
int month = backupTime.Month;
int day = backupTime.Day;
int hour = backupTime.Hour;
int minute = backupTime.Minute;
int second = backupTime.Second;
int ms = backupTime.Millisecond;
String tmestr = backupTime.ToString();
tmestr = "D:\\" + year + "-" + month + "-" + day + "-" + hour + "-" + minute + ".sql";
StreamWriter file = new StreamWriter(tmestr);
ProcessStartInfo proc = new ProcessStartInfo();
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} ", "root", "sa", "localhost", "employee", "backup.sql");
proc.FileName = @"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump";
proc.RedirectStandardInput = false;
proc.RedirectStandardOutput = true;
proc.Arguments = cmd;//"-u root -p smartdb > testdb.sql";
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = p.StandardOutput.ReadToEnd();
file.WriteLine(res);
p.WaitForExit();
file.Close();
MessageBox.Show("Backup Done");
}
catch (IOException ex)
{
MessageBox.Show("Disk full or other IO error , unable to backup!");
}
但是它只在第一张桌子上出现...
我想要整个数据库.
在此先谢谢您……
But its coming for the 1st table only...
I want the whole database.
Thanks in advance......
推荐答案
我只能假设您对Google的搜索不是很好,也不使用了较差的搜索词组.
我刚刚尝试过,使用 c#mysql backup ,而我看到的前几本命中都有代码示例.
I can only assume that you didn''t google very hard, or used a poor search phrase.
I just tried, using c# mysql backup and the first few hits that I looked at had code samples.
这篇关于如何使用c#.net进行MySQL数据库的备份和还原的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文