2010-12-15 14 views
3

C#コードを使用して、ダンプファイルからMySQLデータベースのデータを復元しようとしています。C#MySQLデータベースのリストア

私は、次のコマンドを実行すると仮定しています: mysqlの--verbose --user =ルート--password = qwerty123456テスト< C:Users \ユーザーデフォルト\ testing.SQL

\私はC#は」doesnのことを知っています"<"という記号を認識するので、いくつかの方法を試しましたが、それでも機能しませんでした。誰も私にこれを助けることができますか?私はすべてのデータベースデータをC#コードを使ってMySQLに戻したいと思っています。

ありがとうございます。あなたは、単にUseShellExecute = trueを設定している場合

  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"); 

答えて

2

<取り扱いは(IIRC)OKでなければなりません。あなたが本当にシェルexecを避けたい場合は

はしかし、<入力です - あなたはStandardInputへのファイルの書き込みをしなければなりません。おそらくStandardOutputのままにしておきます(出力を積極的に使わない場合はRedirectStandardOutput = falseに設定してください)。

テストされていないが、多分:

 using(var stdin = process.StandardInput) 
     using(var reader = File.OpenText(@"C:\Users\Default\testing.SQL")) { 
      string line; 
      while((line = reader.ReadLine()) != null) { 
       stdin.WriteLine(line); 
      } 
      stdin.Close(); 
     } 

(はず行毎にファイル内パイプ)

+0

ありがとう!できます。 – athgap

関連する問題