C# 通过C还原MySQL文件#

C# 通过C还原MySQL文件#,c#,mysql,C#,Mysql,我目前正在做一个C。该项目的一部分涉及将SQL文件导入MySQL程序,以将该文件恢复到数据库中 下面是我正在使用的代码 command = string.Format("--host={0} --user={1} --password={2} --port={3} {4} < {5}", MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.Connect

我目前正在做一个C。该项目的一部分涉及将SQL文件导入MySQL程序,以将该文件恢复到数据库中

下面是我正在使用的代码

command = string.Format("--host={0} --user={1} --password={2} --port={3} {4} < {5}",
                        MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.ConnectionKeyStrings.SERVER],
                        MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.ConnectionKeyStrings.USERNAME],
                        MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.ConnectionKeyStrings.PASSWORD],
                        MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.ConnectionKeyStrings.PORT],
                        db.database, restoreFile);
Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            //process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.FileName = @"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe";
            process.StartInfo.Arguments = command;
            process.StartInfo.CreateNoWindow = true;
            process.Start();
            //string output = process.StandardOutput.ReadToEnd();
            string errorOutput = process.StandardError.ReadToEnd();
command=string.Format(“--host={0}--user={1}--password={2}--port={3}{4}<{5}”,
MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.ConnectionKeyStrings.SERVER],
MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.connectionKeyString.USERNAME],
MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.ConnectionKeyStrings.PASSWORD],
MySQLConnectionManager.currentlyUsingConnection[MySQLConnectionManager.ConnectionKeyStrings.PORT],
数据库,恢复文件);
流程=新流程();
process.StartInfo.UseShellExecute=false;
//process.StartInfo.RedirectStandardOutput=true;
process.StartInfo.RedirectStandardError=true;
process.StartInfo.FileName=@“C:\Program Files\MySQL\MySQL Server 5.5\bin\MySQL.exe”;
process.StartInfo.Arguments=命令;
process.StartInfo.CreateNoWindow=true;
process.Start();
//字符串输出=process.StandardOutput.ReadToEnd();
string errorOutput=process.StandardError.ReadToEnd();
不过,我没有收到任何错误,如果重定向标准输出,我只会返回文件的内容,而不是实际执行恢复


谢谢你能提供的帮助

我更像是一个linux程序员,但在我看来,你是在把一个文件名传送到mysql。如果是这样,这是不对的。您应该将sql文件的内容通过管道传输到shell中的mysql,
我更熟悉python和mysql,但我要做的是打开文件并读取它,就像它是一个文本文件一样,去掉任何行尾字符并创建一个sql命令,该命令可以在服务器上执行,以将数据恢复回服务器。我对c#不太了解,因此无法编写示例。希望这能有所帮助。

如果我手动运行该命令mysql--user=myuser--password=password myDB"--host={0} --user={1} --password={2} --port={3} {4} < {5} 2>&1"