.net mysql 备份,如何使用c#.net备份和恢复MySQL数据库

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......

解决方案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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值