2016-04-14 6 views
1

私はこれをトラブルシューティングするのに何時間も費やしています。私はconsole.writelineを見ることによって、このコードprocess.startでmysqldumpを使用すると何も起きませんが、cmdで引数を試してみると、それは動作しています

Dim drive_name As String = Directory.GetCurrentDirectory & "\database" 

    Dim db_name As String = "sample_db.sql" 

    Dim argument As String = "-u root sample_db table1 > """ & drive_name & "\" & db_name & """" 
    Try 
     Diagnostics.Process.Start("C:\xampp\mysql\bin\mysqldump.exe", argument) 
     Console.WriteLine("Argument: " & argument) 
    Catch ex As Exception 
     Console.WriteLine("Error: " & ex.ToString) 
    End Try 

を持って、この

-u root sample_db table1 > "C:\Users\MyName\Desktop\MyProjectPath\bin\Debug\database\sample_db.sql" 

のような、それは出力しかしC:\Users\MyName\Desktop\MyProjectPath\bin\Debug\database\をチェックして、私はsample_db.sqlを見ることができないので、私はmysqdumpがconsole.writelineをコピーし、それを貼り付ける開きますcmd。私は今これをmysqldumpに持っています。

C:\Users\MyName>C:\xampp\mysql\bin\mysqldump -u root sample_db table1 > "C:\Users\MyName\Desktop\MyProjectPath\bin\Debug\database\sample_db.sql" 

これをmysqldumpで実行すると動作します。

これを修正するにはどうすればよいですか?

+1

Imはlessthanの使用に驚いたが、私はgreaterthanを期待していただろう – BugFinder

+0

あ、ごめんなさい!それは単にタイプミスです。 –

+0

:)あなたはprocess.StandardOutputオプションを使用して試してみたことがありますか? – BugFinder

答えて

0

ベースの提案BugFinderstandardInputと標準出力の

を使用できるようになりましたインポート用

コード:

Try 
     Dim myProcess As New Diagnostics.Process() 
     myProcess.StartInfo.FileName = "cmd.exe" 
     myProcess.StartInfo.UseShellExecute = False 
     myProcess.StartInfo.WorkingDirectory = "C:\xampp\mysql\bin\" 
     myProcess.StartInfo.RedirectStandardInput = True 
     myProcess.StartInfo.RedirectStandardOutput = True 
     myProcess.Start() 
     Dim myStreamWriter As StreamWriter = myProcess.StandardInput 
     Dim mystreamreader As StreamReader = myProcess.StandardOutput 
     createDatabase() 
     myStreamWriter.WriteLine("mysql -u root sample_db < " & drive_name & "\" & db_name) 
     myStreamWriter.Close() 
     myProcess.WaitForExit() 
     myProcess.Close() 
    Catch ex As Exception 
     Console.WriteLine("Error on Import: " & ex.ToString) 
    End Try 

インポートし、それを変更したい場合は、単にあなたの希望mysqldumpをexportコマンドにこのコード行を変更するには:exportコマンド

myStreamWriter.WriteLine("mysql -u root sample_db < " & drive_name & "\" & db_name) 

myStreamWriter.WriteLine("mysql -u root sample_db > " & drive_name & "\" & db_name) 
0

In this linkユーザーは、あなたが今

Dim argument As String = "-u root sample_db table1 -r """ & drive_name & "\" & db_name & """" 

を持つことになりますので、代わりに

Dim argument As String = "-u root sample_db table1 > """ & drive_name & "\" & db_name & """" 

>-r

を変更することが示唆されそしてそれは仕事をでしょう!

1

これはmysqlを使っていませんが(私はそれを持っていないので)、プリンシパルが適用されます。

Process p = new Process(); 
p.StartInfo.FileName = @"c:\windows\system32\ipconfig.exe"; 
p.StartInfo.Arguments = @"/all"; 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.RedirectStandardOutput = true; 
p.Start(); 
String output = p.StandardOutput.ReadToEnd(); 
File.WriteAllText(@"c:\log.txt",output); 
p.WaitForExit(); 

(log.txt)は期待通りに出力されました。

ので、あなたの場合には、ファイル名でのmysqldumpコマンドを持って、引数内の引数、および出力ファイルにwritealltextを変更

あなたが望むべきで明らかにあなたがはるかに創造的にこれを使用することができ、用サイズたとえば、gbのデータを持っていれば、問題が発生する可能性があります。すべてを1つの文字列に格納することはおそらく少しは質問しますが、出力はストリームなので、実際にはさらに作業してストリームをより直接的に処理してチャンクを出力できますチャンクで

+0

ありがとう!あなたの例のために、私は今、そのような種類のバックアップと復元を探すことができます。 http://www.codeproject.com/Tips/726407/MYSQL-Database-Backup-Restore –

関連する問題