在C#中进行mysqldump备份不会检索数据 [英] Making mysqldump backup in C# doesn't retrieve data

查看:160
本文介绍了在C#中进行mysqldump备份不会检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从查询创建备份副本的代码,该查询从过去一年中获取较旧的寄存器,并将其保存到* .sql文件中.但是,我发现的问题是当我打开.sql文件时,它为空.我已经在命令提示符下尝试了查询,并且效果很好.

I''ve got a code to create a backup copy from a query, this query takes the older registers from a year in the past and saves them into a *.sql file. But the problem that I found is when I open the .sql file and it''s empty. I''ve tried the query in command prompt and it works perfectly.

try
{
    string strBackupFileName = GetBackUpFileName();
    StreamWriter strBackupFile = new StreamWriter(strBackupFileName);

    ProcessStartInfo psInfo = new ProcessStartInfo();
    psInfo.FileName = @"c:\Users\current.user\source\xampp\mysql\bin\mysqldump.exe";
    psInfo.RedirectStandardInput = false;
    psInfo.RedirectStandardOutput = false;
    psInfo.Arguments = "- u root -h localhost --databases --hex-blob -n -t dashboard --tables dashboard.backup --where='updated_at < NOW() - INTERVAL 365 DAY'";
    psInfo.UseShellExecute = false;
    psInfo.RedirectStandardOutput = true;
    Process backup_process = Process.Start(psInfo);

    string stdout;
    stdout = backup_process.StandardOutput.ReadToEnd();
    strBackupFile.WriteLine(stdout);
    backup_process.WaitForExit();
    strBackupFile.Close();
    backup_process.Close();
    MessageBox.Show("Backup done at file:" + strBackupFileName);
}
catch (Exception ex)
{
    MessageBox.Show("Error during the backup: \n\n" + ex.Message);
}



我尝试过的事情:

当我运行程序时,我发现mysqldump并不等待"执行该过程(当我手动执行该过程时,至少需要25-30秒),它会打开命令提示符窗口并立即关闭



What I have tried:

When I run the program I see that mysqldump doesn''t "wait" to do the process (when I do it manually, it takes at least 25-30 seconds), it opens a command prompt window and closes immediately

推荐答案

psInfo.Arguments = "- u root -h localhost --databases --hex-blob -n -t dashboard --tables dashboard.backup --where='updated_at < NOW() - INTERVAL 365 DAY'";


也许-字符和u之间的空格引起了问题.


Maybe that space between the - character and the u is causing problems.


这篇关于在C#中进行mysqldump备份不会检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆