Access denied for 'root'@'localhost' after upgrade to MySQL 5.7

In most cases where root user was set without a password for MySQL server and after upgrade to MySQL >= 5.7, user experiences difficulty connecting to database using root, getting an "access denied for 'root'@'localhost'" error.

The reason that happens is because the new MySQL installation tries to authenticate root user without password by comparing the username and checking if is connecting using a UNIX socket.

In order to change back to mysql_native_password plugin do the following:

Login to MySQL using sudo:

sudo mysql -u root -p

Execute the following commands:

USE mysql;

UPDATE user SET plugin = 'mysql_native_password' WHERE User='root';