I try to backup and restore MySQL database from C# using process.
First BackUP:
the command to backup database is :
-u USER -pPASS --databases DATABASE -r > path/to/file.sql
Here is my C# code:
Process.Start(@"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe", ("-u user -p***** --databases DB -r \"" + path + "\"";
Look at the difference, in my code is not "
>", becuse it wont work with it. If I put this char to code, it just show me usage of mysqldump in win cmd. Without it, this code work good.
Now i want to restore database.
the command to restore database is :
-u USER -pPASS DATABASE < path/to/file.sql
Here is my c# codes :
1#
Process.Start(@"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe", ("-u user -p**** < \"" + path + "\""));
2#
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.WorkingDirectory = @"C:\Program Files\MySQL\MySQL Server 5.5\bin\";
myProcess.StartInfo.Arguments = "-u user -p**** PIEx < + "\"" + path + "\"";
myProcess.StartInfo.RedirectStandardInput = false;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.Start();
myProcess.WaitForExit();
myProcess.Close();
Both solutions dont work. I think it is becuse of this char "
>", the same problem like backup, but in this case, removing it dont work. The result is same, it write down mysql usages in cmd console.
If I execute this commands manually in cmd (move to mysql bin, then run mysql with arguments), it work fine. I try redirect output/input/error to stream readers/writers - not work. Try to UseShellExecute = true - not work. Nothing works.
Help me guys. Thx