php - I got ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) with the command sudo mysql on ubuntu

I am really a noob in all this stuff like php or sql so I took a coursera course where they told us to install LAMP.

I have Linux and Apache2 but for MySql, I followed this tutorial how to install LAMP. I followed it and after the place where we have to run sudo mysql, I got ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO). but according to the tutorial I should get:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.19-0ubuntu5 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Please can anybody help me with this as soon as possible because the course I am doing has a deadline. Also if any documentation available on the web, please share.

if you need some more information on the error, please tell me and also how to extract them.

Thank you.

EDIT: my problem was solved and I was able to enter the password after I ran mysql -u root -p

Answer

Solution:

Hi try below commands in your mysql console

mysql>  FLUSH PRIVILEGES;
mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Source