c# - 如何以编程方式调用和执行MySQL命令?

标签 c# mysql cmd

我想以编程方式运行所有命令,命令如下:

string mysql ="C:\Program Files\MySQL\MySQL Server 5.1\bin"
string command =" mysql.exe -u root -ppassword fabrica < c:/backup.sql";

我想使用 C# 运行这两行,我该如何实现?

最佳答案

编辑:现在我知道你到底想做什么

这里是一个方法中的代码

string binary = @"C:\MySQL\MySQL Server 5.0\bin\mysqldump.exe"
string arguments = @"-uroot -ppassword sample"
ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo(binary, arguments);
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
Process p = System.Diagnostics.Process.Start(PSI);
Encoding encoding = p.StandardOutput.CurrentEncoding;
System.IO.StreamWriter SW = new StreamWriter(@"c:\backup.sql", false, encoding);
p.WaitOnExit();
string output = p.StandardOutput.ReadToEnd()
SW.Write(output)
SW.Close();

祝你好运!

关于c# - 如何以编程方式调用和执行MySQL命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13748827/

相关文章:

c# - 注册事件,为什么代码可以编译不报错?

c# - 在 Azure 中使用 Identity Server 签名证书

c# - Unity3d:通过GetComponent错误从另一个脚本访问类

php - 内连接不起作用

cmd - 如何从 REG QUERY 获取特定列?

c# - 如何将 LINQ 与二维数组一起使用

php - MySQL 条件连接查询(WordPress 数据库)

mysql - 从 MySql 导出到 sql 文件时如何自动转义内容中的引号?

batch-file - 用于运行批处理文件的 GUI

google-chrome - 通过Powershell启动过程在新标签页而不是新窗口中打开Chrome