Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = false; p.Start(); String command = ""; //mysql dump 存放位置 String mysqlDumpPath = @"C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin"; command = "cd " + mysqlDumpPath; //執行command p.StandardInput.WriteLine(command); //要進行backup 的db名稱 String dbName = "testdb"; String outputPath = @"C:\" + dbName; //創建存放資料夾 if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } //注意 -p後緊接你的MYSQL密碼 command = "mysqldump -u 你的MYSQL帳號 -p你的MYSQL密碼 " + dbName + " > " + outputPath + "\\" + dbName + ".sql"; //執行command p.StandardInput.WriteLine(command);
C#, MySQL, Programming, SQL