mysql access denied for user root

Developer from somewhere

Faced this error: Access denied for user ‘root’@’localhost’ (using password: YES) (Mysql2::Error)

Found the fix here:

$ mysql -u root mysql
$mysql> UPDATE user SET Password=PASSWORD('my_password') where USER='root';
$mysql> FLUSH PRIVILEGES;

but the 2nd variant was the one that worked in my case:

update user set authentication_string=password('my_password') where user='root';