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:
> 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.