MySQL is an open-source relational database, made famous by its ease-of-use and simple setup on modern Linux and Windows operating systems. On an unmodified MySQL install, the root user account does not have a password. This is extremely insecure!
If you have installed mysql first time and no password has been assigned against the root user then login directly as root user by typing below
sudo mysql
You will see a screen like below
Then update the password with below command
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
What the above command-line does, is it changes the password for the user root and sets the authentication method to mysql_native_password. This is a traditional mode of authentication
Then run
FLUSH PRIVILEGES; exit;
Restart the mysql
sudo service mysql restart
Then you can login to mysql with the command
mysql -u root -p
Input the passcode you used with the ALTER USER command and do not input the system password to try and access MySQL because it will not work. You should now see the MySQL welcome message if it all went well.