2010-12-15 9 views
3

C# 코드를 사용하여 덤프 파일에서 MySQL 데이터베이스 데이터를 복원하려고합니다. \ 기본 testing.SQLC# MySQL 데이터베이스 복원

\ 내가 C 번호는 '아무튼 알고 \ 사용자 : MySQL의 --verbose --user = 루트 --password = qwerty123456 시험 < C :

나는 다음과 같은 명령을 실행한다고 가정하고 t는 "<"기호를 인식하므로 여러 가지 방법을 시도했지만 여전히 작동하지 않았습니다. 아무도 이걸 도와 줄 수 있니? 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) 확인을해야합니다. 당신이 정말로 쉘 간부를 방지하려면

그러나, <입력 - 당신은 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