C # MySQL database recovery

I am trying to recover MySQL database data from a dump file using C # codes.

I suppose to run the following command: mysql --verbose --user = root --password = qwerty123456 test <C: \ Users \ Default \ testing.SQL

I know that C # does not recognize "<" so I tried several methods, but it still did not work. Can someone help me with this? I want to restore all the data in my database back to MySQL using C # codes.

Thanks in advance.

            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");
+3
source share
1 answer

Handling <should be fine (IIRC) fine if you just install UseShellExecute = true.

, 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();
        }

( )

+2

Source: https://habr.com/ru/post/1780369/


All Articles