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
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
sudo service mysql start