Ubuntu – How to reset thesql root password without logging into thesql

MySQLpassword

I want to reset mysql root password but I don't want to log into mysql and then reset the password just as follows,

  mysql -u root
  FLUSH PRIVILEGES;
  SET PASSWORD FOR root@'localhost' = PASSWORD('password');
  UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';

Is there a way to achieve this using external command or something?

Best Answer

sudo dpkg-reconfigure mysql-server-x.x

Replace x.x with your current mysql server version.

Than it will prompt for a new password.

Related Question