MySQL

MySQL installation on Ubuntu 20.04 error when using mysql_secure_installation

I’m trying to install MySQL on Ubuntu 20.04 and when I run the command sudo mysql_secure_installation, it fails with the error below:

… Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.`

I have seen the documentation and I’m stuck on how I can solve this.

Any help will be appreciated.

 

Answer

 

Had the same error, solved it by running sudo mysql which logged me in as root without a password, then I ran ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';

Following this I was able to run mysql_secure_installation again and this time I got to choose to use existing password (the one I set with above SQL command).

However now I can no longer login without a password, running sudo mysql now denies root user access.