I think it is important to note on this older post that MySQL has changed some things in the past 5 years. Digital Ocean states the following in their tutorial called How To Install MySQL on Ubuntu 18.04:
In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the
auth_socket plugin by default rather than with a password.
Therefore, run the following to install properly and securely:
sudo apt update
sudo apt install mysql-server
I personally answered
y for every prompt from the
mysql_secure_installation and created a strong password (option
2, if you set up the VALIDATE PASSWORD plugin). However, the particular choices here are your's to make. Either way, you will set a password under one of these prompts. Although, as you will see, you won't necessarily need the password.
After the prompts for
mysql_secure_installation are complete. All you have to do is type the following to log in:
This is because the native authentication method for MySQL 5.7 and later is
auth_socket instead of
mysql_native_password for better security. No need for a password, because you can only log in from the machine it's installed on.
If you need to use a password to log in from another source, or want to know more, I recommend reading How To Install MySQL on Ubuntu 18.04 in its entirety.