返回首页

我想借此MySQL数据库的备份,我已经尝试下面的代码,不正常工作


 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 = "C:\\" + 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} >  {4};", "root", "", "localhost", "globasys", "backup.sql");

                    proc.FileName = @"C:\Program Files\MySQL\MySQL Server 6.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();

 

此代码创建。 SQL文件,但是当这个文件恢复到的数据显示错误消息SQL转储错误后txt文件显示错误消息
{C}如何在C#中MySQL数据库的备份。

回答

评论会员: 时间:2