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();
}
-pflag tomysqlprompts 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 ifmysql.exedoesn't exist or the MySQL server isn't responding?