How to Install MySQL on Ubuntu 20.04 {5-Step Process} – phoenixNAP



is one of the most popular and widely used open source relational database management systems


It is a fast, simple, and scalable SQL-based system, and represents an integral component of the LAMP stack that runs much of the Internet


In this tutorial, you will learn how to install MySQL on Ubuntu 20.04.

<img src="" alt="How to install

MySQL on Ubuntu 20.04″ />


A system running Ubuntu 20.04

  • A user account with sudo privileges
  • Access to a terminal (Ctrl + Alt + T)
  • Network connection
  • Install MySQL on Ubuntu 20.04 Hosting MySQL databases on

  • Ubuntu 20.04

requires installation of the MySQL server package. You can also access the database from remote clients using MySQL Client.

Follow these simple steps to install MySQL Server on Ubuntu 20.04.

Step 1: Update/update

the package repository

Update the system package repository to ensure that you are installing the latest version of MySQL


1. Open the terminal and run the following command:

sudo apt update

2. Enter your password and wait for the update to finish.

3. Then run:

sudo apt upgrade

4. Enter Y when prompted to proceed with the update and press ENTER. Wait for the update to finish.

Step 2: Install MySQL

1. After successfully updating the package repository, install MySQL Server by running the following command:

sudo apt install mysql-server

2. When asked if you want to continue with the installation, answer Y and press ENTER.

Install MySQL server on Ubuntu.

The system downloads MySQL packages and installs them on your machine


3. Check if MySQL was installed correctly by running

: mysql -version

The result shows which version of MySQL is installed

on the machine.

Step 3: Protect


instance on your machine is insecure immediately after


1. Protect your MySQL user account with password authentication by running the included security script:

sudo mysql_secure_installation

Secure the MySQL server by setting an authentication password.

2. Type your password and answer AND when prompted to continue configuring the VALIDATE PASSWORD component. The component checks whether the new password is strong enough.

3. Choose one of the three password validation levels:

  • 0 – Low. A password that contains at least 8 characters.
  • 1 – Medium. A password that contains at least 8 characters, including numeric characters, mixed case characters, and special characters.
  • 2 – Strong. A password that contains at least 8 characters, including numeric characters, mixed case characters, and special characters, and compares the password to a dictionary file.

Type 0, 1, or 2 depending on the strength of the password you want to set. The script then prompts you to enter your password and re-enter it afterwards to confirm.


subsequent MySQL user password must match

the strength of the selected password.

The program estimates the strength of your password and requires confirmation to proceed


4. Press Y if you are satisfied with the password or any other key if you want a different one.

5. Next, the script requests the following security features:

  • Delete anonymous users
  • ?

  • Don’t allow root login remotely
  • ?

  • Delete the test database and access it
  • ?

  • Reload privilege tables now?

The recommended answer to all these questions is Y. However, if you want a different setting for any reason, enter any other key.

For example, if you need the remote logon option for the server, type any non-Y key for that message.

Step 4: Check if the MySQL service is running After installing MySQL successfully, the MySQL service starts automatically. Verify that the MySQL server is running running: sudo systemctl status mysql

The output should show that

the service is operational and running:

How to check if the MySQL service is running on Ubuntu.

Step 5: Log

in to MySQL Server Finally, to log in to the

MySQL interface, run the following command:

sudo mysql -u root

Log in to MySQL Shell in Ubuntu terminal.

You can now run queries, create databases, and test your new MySQL configuration. Take a look at our MySQL command cheat sheet for some important MySQL commands.


You should now have a fully functional MySQL server installed on your machine. Start exploring the vast possibilities of MySQL and try out the various features it has to offer.

Become an advanced MySQL user by reading our tutorials for MySQL Events, MySQL JOINS, MySQL Stored Procedures, and MySQL Triggers.

Contact US