C# MySQL 数据库恢复
我正在尝试使用 C# 代码从转储文件恢复 MySQL 数据库数据。
我应该执行以下命令: mysql --verbose --user=root --password=qwerty123456 测试 < C:\Users\Default\testing.SQL
我知道 C# 无法识别“<”符号所以我尝试了几种方法但仍然不起作用。有人能帮我解决这个问题吗?我想使用 C# 代码将所有数据库数据恢复到 MySQL。
提前致谢。
Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe";
process.StartInfo.Arguments = @"--verbose --user=root --password=qwerty123456 test";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
StreamReader sr = process.StandardOutput;
sr = File.OpenText(@"C:\Users\Default\testing.SQL");
I am trying to restore MySQL database data from a dump file, using C# codes.
I am suppose to execute the following command:
mysql --verbose --user=root --password=qwerty123456 test < C:\Users\Default\testing.SQL
I know that C# doesn't recognise the "<" symbol so I tried several ways but it still did not work. Can anybody help me with this? I want to restore all my database data back into MySQL using C# codes.
Thanks in advance.
Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe";
process.StartInfo.Arguments = @"--verbose --user=root --password=qwerty123456 test";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
StreamReader sr = process.StandardOutput;
sr = File.OpenText(@"C:\Users\Default\testing.SQL");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只需设置
UseShellExecute = true
,<
处理应该 (IIRC) 没问题。但是,如果您确实想避免 shell 执行,
<
是一个输入 - 您应该将文件写入StandardInput
。我可能会单独保留StandardOutput
(如果您不主动想要输出,请设置RedirectStandardOutput = false
)。未经测试,但也许:(
应该逐行输入文件)
The
<
handling should (IIRC) be OK if you simply setUseShellExecute = true
.However, if you really want to avoid the shell exec,
<
is an input - you should be writing the file toStandardInput
. I'l probably leaveStandardOutput
alone (setRedirectStandardOutput = false
if you don't actively want the output).Untested, but maybe:
(which should pipe in the file line by line)