Recently, the MySQL package on Ubuntu was changed, so the user is no longer prompted to enter the password during installation. These instructions will help you set the password on Ubuntu 18.04, 18.10, 19.04, 19.10, 20.04, and others.
Step 1. Install MySQL server (if you haven’t already)
apt install -y mysql-server php-mysql
Step 2. Setup password authentication method
mysql -u root
USE mysql; UPDATE user SET plugin='mysql_native_password' WHERE User='root'; FLUSH PRIVILEGES; exit;
service mysql restart
Step 3. Set the root password
Enter current password for root (enter for none): Just press Enter Set root password? [Y/n]: Y New password: Enter password Re-enter new password: Repeat password Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y
Step 4. Test the settings
mysql -u root -p
Try with no password and with correct password.