我试图制作一个C#函数,从MySQL服务器进行数据库转储。您可能知道,MySQL要求输入如下密码:
所以这就是我所做的:
success: function(msg){
alert( "Data Saved: " + msg );
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("some error");
}
当我执行此功能时,进程启动并等待用户写入密码,但public static bool BackupDatabase(string filename)
{
try
{
string mysqldumpdir = @"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqldump.exe";
string user = "root";
string password = "root";
string databases= "hrsmarttest7";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = mysqldumpdir,
RedirectStandardInput = true,
Arguments = string.Format("--user {0} --password --databases {1} --result-file=\"{2}\"", user, databases, filename),
UseShellExecute = false,
CreateNoWindow = true
};
var mysqldump = new Process { StartInfo = startInfo, EnableRaisingEvents = true };
mysqldump.Start();
System.Threading.Thread.Sleep(3000);
mysqldump.StandardInput.AutoFlush = true;
mysqldump.StandardInput.Write(password+"\n"); // this doesn't do the job !!!
mysqldump.WaitForExit();
mysqldump.Close();
return true;
}
catch (Exception e)
{
//RecordException(e);
return false;
}
}
没有写入密码,我必须终止程序以结束我的程序。
请帮忙。