If what colleague @AlfredoPaz has placed in your answer does not work, you could try the following:
1) Go to / etc and edit the file my.cnf (/etc/my.cnf)
- Then under the line mysqld place:
skip-grant-tables-under
2) Restart the MySQL service with the command associated with your Linux distro.
3) Try entering MySQL again using the command:
mysql -u root
4) Place a new password by executing:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
Where 'PasswordAquí' is the password you wish to place for your root user.
5) Then you execute:
flush privileges;
6) You return to the file from the beginning and edit it (/etc/my.cnf) to eliminate what you had added before, that is:
skip-grant-tables
7) Restart MySQL again with the command associated with your Linux distro
8) Try again:
mysql -u root
By now you should be able to enter without problems.
I had a problem similar to yours and I managed to solve it in this way, guiding me from the solution provided by a StackOverflow user who speaks English, specifically the user is called @KishoreVenkataramanan. Your solution worked perfectly for me. I have translated your solution into Spanish so that you and other SO users will be as useful as the OS users.
If you want to see your answer you can access MySQL Error:: 'Access denied for user 'root' @ 'localhost'
I hope it helps. A greeting!