'mysql uroot password in UBUNTU

I get this error "access denied for user 'root'@'localhost' (using password no)" to which i've found a temporary solution to. I do in the terminal:

  1. sudo service mysql stop (Enter my password)
  2. (Then I navigate to usr/bin) and type: sudo mysqld_safe --skip-grant-tables
  3. (Open a new Terminal and type): mysql use mysql; UPDATE user SET password=PASSWORD('I_enter_my_new)password') WHERE user= 'root'; exit sudo service mysql start (then I enter my password)

This works fine only until I shut down my pc and log back in again . I would like a permanent solution to this please if anyone has one.



Solution 1:[1]

Try doing all the --skip-grant-tables jazz, hop into mysql and do that:

grant all privileges on *.* to 'root' identified by 'newpassword' with grant option;
flush privileges;
quit;

Then you can restart the service and try logging in with mysql -uroot -p and enter the new password.

Hope that helps

Solution 2:[2]

One thing: a command like

grant all privileges on *.* to 'root' identified by 'newpassword' with grant option;

will remain in the history, who knows for how long. Be careful in production, do not put 'newpassword' in cleartext but in the hashed form, or disable history:

export MYSQL_HISTFILE=/dev/null && mysql -u root

Solution 3:[3]

As mentioned at

https://stackoverflow.com/a/8789560/631619

The root user password is an empty string by default.

And (using password: NO) says that there is no password.

Did you try $ mysql -uroot ?

Also, I'm not sure if you should be stop and starting with sudo.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jfornoff
Solution 2 sc0p
Solution 3 halfer