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
  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?

  • 2
    You could enter the above lines in a text file and use a command like mysql -u root < resetpassword.txt. Or you could restart the server with mysqld_safe --init-file=/home/me/resetpassword.txt &. – Jos Feb 12 '15 at 8:08
sudo dpkg-reconfigure mysql-server-x.x

Replace x.x with your current mysql server version.

Than it will prompt for a new password.

Try follows:

mysqladmin -u root password **your-new-password**

sudo /etc/init.d/mysql restart

mysql -u root -p

Give password to enter mysql.

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.