我正在编写一个应用程序,它应该创建一个数据库的完整副本,然后使用不同的名称将其导入到同一个服务器上。
所以,我想我应该使用mysqldump和mysql以及我应该传递给它们的参数。
好的,但我无法将转储文件放在我想要的位置,因为我必须知道位置,然后将它传递给mysql。
C#和mysqldump
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();
我做错了什么,但我不知道是什么。
mysqldump命令是否像命令行那样工作?运行你的c#的用户是否有权限运行mysqldump? – mconlin 2013-05-10 13:52:35
试着把1放在1之前> like 1> C:\\ ......' – Steve 2013-05-10 13:58:12
当我在CMD中运行完全相同的命令时,一切正常,但是当我运行我的项目时什么也没有发生。 – 2013-05-10 14:09:53