How to Install MySQL Database on Ubuntu 18.04 / 20.04 via Terminal?

To install MySQL on Ubuntu operating system, simply follow the steps below:

  1. Open your terminal and run the following update command:
  2. 
        sudo apt update
    
  3. Run the following command to install MySQL:
  4. 
        sudo apt install mysql-server
    
  5. When you see "Do you want to continue? [Y/n]" during the installation process, type y and hit enter.
  6. Next, configure MySQL security, by running the following command:
  7. 
        sudo mysql_secure_installation
    
  8. Again, when you see "Press y|Y for Yes, any other key for No:", press y and hit enter.
  9. Next, you will need to configure your MySQL password validation policy. If you want the MySQL database accessing user's password to be strong then select 2. I am selecting 1 which is medium.
  10. Next enter password of your choice.
  11. When you see "Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No)", press y and hit enter.
  12. When you see "Remove anonymous users? (Press y|Y for Yes, any other key for No)", press y and hit enter.
  13. When you see "Disallow root login remotely? (Press y|Y for Yes, any other key for No), press y if you do not want to allow access to your MySQL from remote computer else press n and hit enter.
  14. Press n when you see "Remove test database and access to it? (Press y|Y for Yes, any other key for No)" and hit enter.
  15. When you see "Reload privilege tables now? (Press y|Y for Yes, any other key for No)", press y and hit enter.
  16. Next, open MySQL in your terminal by using the following command:
  17. 
        sudo mysql
        
  18. Run the following MySQL command to update root user's password (I am updating my MySQL root user's password to TestPass123$):
  19. 
        ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'TestPass123$';
        
  20. Next, run the following MySQL command to flush privileges:
  21. 
        FLUSH PRIVILEGES;
        
  22. Now, after installing MySQL, lets install MySQL Workbench by running the following command one by one:
  23. 
    sudo apt update
    sudo apt install mysql-workbench
            

    Press y when you are asked to continue. After the installation is complete, you can open MySQL Workbench from the search.

Installation of MySQL is complete.