C#和mysqldump [英] C# and mysqldump

查看:255
本文介绍了C#和mysqldump的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,该应用程序应该完成一个数据库的副本,然后将其导入到具有不同名称的同一台服务器上。

所以我想我应该使用mysqldump和mysql我应该传给他们的参数。

好​​的,但是我不能得到转储把文件放在我想要的地方,因为我必须知道位置,然后把它传递给mysql。 >

  StringBuilder exportPath = new StringBuilder(); 
//exportPath.Append(Directory.GetCurrentDirectory());
exportPath.Append(@> C:\Temp\backup.sql);

处理MySQLDump = new Process();
MySQLDump.StartInfo.UseShellExecute = true;
//MySQLDump.StartInfo.RedirectStandardOutput = true;
MySQLDump.StartInfo.FileName =mysqldump;
MySQLDump.StartInfo.Arguments =-u root -proot -h localhost mytable+ exportPath;
MySQLDump.Start();
// string theDump = MySQLDump.StandardOutput.ReadToEnd();
MySQLDump.WaitForExit();
MySQLDump.Close();

我做错了,但我不知道什么。

解决方案

您有两种选择:




  • 不要重定向在命令行中输出mysqldump,但是使用更加灵活的进程创建并挂接mysqldump的标准输出。这使得可以对文件进行后处理(以Hash为例),并将其写入所需的位置,或直接将其运行到导入实例的标准输入。

  • 了解,> C:\\Documents和Settings \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\您需要sssemble和参数和重定向部分字符串,并使用 shell执行。确保使用绝对路径名。


I'm writing an application which should make a complete copy of one database and then import it on the same server with different name.
So, I guess I should use mysqldump and mysql and the parameters that I should pass to them.
Okay, but I can't get the dump put the file where I want, because I have to know the location and then pass it to mysql.

StringBuilder exportPath = new StringBuilder();
//exportPath.Append(Directory.GetCurrentDirectory());
exportPath.Append(@" > C:\Temp\backup.sql");

Process MySQLDump = new Process();
MySQLDump.StartInfo.UseShellExecute = true;
//MySQLDump.StartInfo.RedirectStandardOutput = true;
MySQLDump.StartInfo.FileName = "mysqldump";
MySQLDump.StartInfo.Arguments = "-u root -proot -h localhost mytable" + exportPath;
MySQLDump.Start();
//string theDump = MySQLDump.StandardOutput.ReadToEnd();
MySQLDump.WaitForExit();
MySQLDump.Close();

I'm doing something wrong, but I don't know what.

解决方案

You have two choices:

  • Do not redirect the output of mysqldump in the command line, but use a more verbouse process creation and hook the standard output of mysqldump. This makes ist possible to postprocess the file (Hash it as an example) and either write it out to where you want, or run it directly into the standard input of the importing instance.
  • Understand, that > C:\\Documents and Settings\\admin\\Desktop\\databases\\db.sql is not a command line parameter. You need to sssemble and the parameter and redirection part string and use shell execution. Make sure, you use an absolute path name.

这篇关于C#和mysqldump的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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