How to reset/change MySql root password command line in ubuntu linux

Here I’ll show you How to reset/change MySql root password command line in ubuntu linux, Using some mysql CLI commands you can easily recover your mysql administrative password. As I forgot to my mysql root password then i use below commands to reset my mysql root password and it works like charm.

Error:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ 
(using password: NO)

Then i followed the below steps to reset it

Step-1: First login to your ubuntu server using ssh and stop mysql server.

sudo /etc/init.d/mysql stop

OR

sudo service mysql stop

Step-2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password.

 sudo mysqld_safe --skip-grant-tables &


Step-3: Connect with mysql server as root user by running below command on terminal.

sudo mysql -u root

Step-4: Set new mysql root user password.Just replace “NewPassword” with your desired password in below command.

UPDATE user SET Password=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES; exit;

Step-5: All done now restart mysql server.

sudo /etc/init.d/mysql start

OR

sudo service mysql start

If you like this post please don’t forget to subscribe my public notebook for more useful stuff

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.