Linux Mint 19/Ubuntu 18.04 Access denied for user 'root'@'localhost'

On a fresh installation of Linux Mint 19 and Ubuntu 18.04 you can get errors like:

  • ERROR 1045 (28000): Access denied for user 'myuser'@'localhost' (using password: NO)
  • ERROR 1698 (28000): Access denied for user 'root'@'localhost'

This will happen if you try to login in MySQL with:

mysql -u root

In order to log in you will need to use:

sudo mysql -u root

Then enter your OS user password and you will be successfully logged in. After this you can reset your root password to nothing by:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

or set new password by:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

You can find more information here:

MySQL 8 Set or reset user password