c# - 为什么以编程方式转储 MySQL 数据库与通过命令行转储不同?

标签 c# .net mysql startprocessinfo

要从命令行转储数据库,我需要做的是:

mysqldump -uroot --password=  myDb --routines> "C:\s.sql"

所以我想以编程方式尝试的就是这个,我想这是对其的直接解释:

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = dumpUtilityPath;
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;

psi.Arguments = "-uroot --password=  myDb --routines> \"C:\\s.sql\"";

Process process = Process.Start(psi);
process.WaitForExit();
process.Close();

这根本不起作用。相反,我必须去寻找这个,它可以在整个网络上找到,这也有效。

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = dumpUtilityPath;
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;

psi.Arguments = string.Format("-R -u{0} --password={1} -h{2} {3} --routines", "root", "", "localhost", "myDb");

Process process = Process.Start(psi);
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
process.Close();

using (StreamWriter writer = new StreamWriter("C:\\s.sql"))
{
    writer.WriteLine(output);
    writer.Close();
}
  1. 为什么我需要使用流编写器来获取 sql 文件中的数据库,而我可以直接从命令提示符中的命令执行此操作?

  2. 第二个 block 中 -R 的作用是什么?

最佳答案

  1. 您不能在参数中使用“">”重定向 stdout,因为这是命令提示符的一项功能。

  2. -R 在转储中包含存储过程和函数。参见 http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_routines了解更多信息。

关于c# - 为什么以编程方式转储 MySQL 数据库与通过命令行转储不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9547960/

相关文章:

c# - 在 Windows Phone 8.1 共享合约中显示 Viber、Whatsapp

c# - Binding.SourceUpdated 未触发

c# - 是否可以在 application_start 中使用 fluent migrator?

C#/.NET 4.0 创建自定义 configElements 和 configCollection

c# - signalR性能游戏数据实时刷新

php - 存储过程准备语句错误mysql php

mysql - 如何在生产中重命名表和某些列

c# - 将字符串数组与删除和拆分函数组合到一行代码中?

c# - 检查两个 XML 文件在 C# 中是否相同?

mysql - 如何获取按特定列排序后除前5条记录外的所有记录