只是另一个问题。
我有一个C#项目,它具有备份和恢复在线MySQL数据库的功能。备份功能运行良好,但我似乎无法使恢复功能在线工作。它适用于本地数据库。
这是我的恢复功能代码:
private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
{
//restoreFile is an OpenFileDialog
restoreFile.Title = "Restore Database";
restoreFile.FileName = "";
restoreFile.Filter = "MySQL Dump (*.sql)|*.sql";
DialogResult dr = restoreFile.ShowDialog();
if (dr == DialogResult.OK)
{
string filepath = restoreFile.FileName;
StreamReader file = new StreamReader(filepath);
string input = file.ReadToEnd();
file.Close();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "mysql";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = false;
psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}", "uName", "pass", "localhost", "database");
psi.UseShellExecute = false;
Process process = Process.Start(psi);
process.StandardInput.WriteLine(input);
process.StandardInput.Close();
process.WaitForExit();
process.Close();
MessageBox.Show("Database was successfully restored!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
非常感谢任何帮助。谢谢!
答案 0 :(得分:1)
替换psi.FileName =“mysql”;同 psi.FileName =“C:/wamp/bin/mysql/mysql5.5.24/bin/mysql.exe”;