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, 2015 at 8:08

2 Answers 2

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 agree to our terms of service, privacy policy and cookie policy

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