I\'m setting up a new server and keep running into this problem.
When I try to login to the MySQL database with the root user, I get the error:
in my case,
dev@Dev-007:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
I am sure my password was correct otherwise error code would be ERROR 1045 (28000): Access denied for user
so i relogin using sudo,
dev@Dev-007:~$ sudo mysql -u root -p
this time it worked for me . see the docs
and then change root password,
mysql> alter user 'root'@'%' identified with mysql_native_password by 'me123';
Query OK, 0 rows affected (0.14 sec)
mysql>
then restart server using sudo /etc/init.d/mysql restart