Home Linux ServerWeb Server Install MySQL on Ubuntu 20.04

Install MySQL on Ubuntu 20.04

by Thạch Phạm
Published: Last Updated on

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

I. Introduction

MySQL is an open-source database management system, usually installed as part of systems using the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl). It implements the relational model and uses Structured Query Language (also known as SQL for short) to manage its data.

This tutorial AZDIGI will describe how to install theMySQL 8.0 version on the Ubuntu 20.04 server. Once the installation is complete, you will have a working database that you can use to serve your other websites or applications.

Prerequisites: A server running Ubuntu 20.04 with an administrative user as root or a user with sudo privileges and a firewall configured with UFW.

II. Install MySQL on Ubuntu 20.04

To install MySQL on Ubuntu 20.04, we need to do the following 3 steps.

Step 1: SSH into your Ubuntu 20.04 system

To install MySQL on Ubuntu 20.04, we first need to SSH or access your VPS/server as root or a user with sudo privileges. If you don’t know how to SSH into your VPS/Server, you can refer to the following tutorial:

After successfully SSH as root, we continue with step 2 to perform the MySQL installation commands on Ubuntu 20.04.

Step 2: Execute the command Install MySQL on Ubuntu 20.04

On Ubuntu 20.04, you can install MySQL using the APT package repository. At the time of this writing, the version of MySQL available in the Ubuntu repositories defaults to version 8.0.22.

To install MySQL, we’ll need to update the package index on your server in case you haven’t done so recently:

AZDIGI Tutorial
sudo apt update 

After the update is complete, we proceed to install the mysql-server package with the following command:

AZDIGI Tutorial
sudo apt install mysql-server

When asked, select Y to allow the installation to continue.

1 2
Install MySQL on Ubuntu 20.04.
MySQL installation on Ubuntu 20.04 is complete.

This will install MySQL but won’t ask you to set a password or make any other configuration changes. So this will make your MySQL installation unsafe because the configuration is only at the default level, we will deal with this in the next steps.

After the installation is complete, use the mysqld -V command to check the installed version of MySQL.

The MySQL version just installed is Ver 8.0.22.

Step 3: Initial MySQL Configuration

For new installations of MySQL, you will need to run the included security script of the DBMS (Database Management System). This script will help change less secure default options for credentials, remote permissions, anonymous users, and database tests.

You need to run the following command:

AZDIGI Tutorial
sudo mysql_secure_installation

This will take you through a series of questions where you can make configuration changes to security options after installing MySQL.

The first question is whether you want to set up password authentication or not, you can also set the difficulty level of the password. After you set the password, the system will also check the password strength you have set for new MySQL users before deeming them valid or not.

If you choose to set up requiring authentication passwords, any MySQL users you create will need to authenticate with a password and be required to have a password that meets the policy you choose. To claim the strongest password policy – which you can choose by entering 2 – will require the password to be at least eight characters long and consist of a mixture of uppercase, lowercase, numeric and special characters.

Whether you choose to set up an authentication password or not, the next question will be to set a password for the MySQL root user. Enter the password and then confirm the password again.

And the next question is, do you want to remove anonymous users? You should delete these users.


In the next 3 options, you will be asked for the following information:

  • Do you want to disable remote access with the root user? This depends on your needs. If you want security, you should choose No.
  • Do you want to delete the test database? Usually, you should choose Yes because it has almost no practical application.
  • Is there a requirement to reload privileges? The default is Yes in almost all cases.

After the configuration is complete, you can completely access the MySQL administration with the mysql -u root -p command and enter the MySQL root password that you configured earlier.

AZDIGI Tutorial
mysql -u root -p

As root, you have full rights to be able to create users, databases and many other operations you want.

At this point, our installation of MySQL on Ubuntu 20.04 is complete.

III. Summary

As you can see, installing MySQL on Ubuntu 20.04 is relatively easy. In the next article, AZDIGI will introduce how to use MySQL with the command to help you get acquainted with how to create a database, a user, and how to enable remote access for that user.

If you need assistance, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign