1

reset phpmyadmin root password by Execute a Command in cmd using c#. I tried many methods but failed. Here is my code

      public void setmysqlpassword()
    {

ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.WorkingDirectory = @"c:\xampp\mysql\bin"; 
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;

Process process = Process.Start(processStartInfo);

if (process != null)
{

    process.StandardInput.WriteLine("mysql.exe -h localhost -u root -p");

      process.StandardInput.WriteLine("SET PASSWORD FOR root@localhost=PASSWORD('newpassword');");


    process.StandardInput.Close(); hanging on ReadToEnd()

    string outputString = process.StandardOutput.ReadToEnd();

}
2
  • see stackoverflow.com/questions/4116425/… Commented Feb 7, 2015 at 10:58
  • For one thing, the -p flag to mysql prompts you for the password (unless you actually provide a password there directly), so you need to either code a way to answer that to the prompt or provide it as part of the command line. Try running the command at the shell yourself to see. For another, you should deal with error conditions; what if mysql.exe doesn't exist or the MySQL server isn't responding? Commented Feb 9, 2015 at 21:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.