Today’s guide describes the installation of MySQL 8.0 on Ubuntu 20.04. MySQL is one of the most commonly used Database Management Systems. It uses the concept of relational databases and has a client/server architecture. It can be installed on various operating systems including Windows, CentOS and Debian among others.

Installing MySQL 8.0 on Ubuntu 20.04

The below steps describe how to install and configure MySQL 8.0 on Ubuntu 20.04.

Step 1: Add MySQL APT repository in Ubuntu

Ubuntu already comes with the default MySQL package repositories. In order to add or install the latest repositories, we are going to install package repositories. Download the repository using the below command:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb

Once downloaded, install the repository by running the command below:

sudo dpkg -i mysql-apt-config_0.8.16-1_all.deb

he next prompt shows MySQL 8.0 chosen by default. Choose the first option and click OK

How to install mysql 8.0 on ubuntu 20.04 06

In the next prompt, select MySQL 8.0 server and click OK.

How to install mysql 8.0 on ubuntu 20.04 01

The next prompt selects MySQL8 by default. Choose the last option Ok and click OK.

Step 2: Update MySQL Repository on Ubuntu 20.04

Run the below command to update your system packages index list.

sudo apt-get update

Now search for MySQL 8.0 using apt cache as shown below:

$ sudo apt-cache policy mysql-server
mysql-server:
  Installed: (none)
  Candidate: 8.0.23-1ubuntu20.04
  Version table:
     8.0.23-1ubuntu20.04 500
        500 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 Packages
     8.0.23-0ubuntu0.20.04.1 500
        500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu focal-updates/main i386 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages
        500 http://mirror.hetzner.de/ubuntu/packages focal-updates/main amd64 Packages
        500 http://mirror.hetzner.de/ubuntu/packages focal-updates/main i386 Packages
        500 http://mirror.hetzner.de/ubuntu/packages focal-security/main amd64 Packages
        500 http://mirror.hetzner.de/ubuntu/packages focal-security/main i386 Packages
     8.0.19-0ubuntu5 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu focal/main i386 Packages
        500 http://mirror.hetzner.de/ubuntu/packages focal/main amd64 Packages
        500 http://mirror.hetzner.de/ubuntu/packages focal/main i386 Packages

Step 3: Install MySQL 8.0 on Ubuntu 20

Having found MySQL 8.0 in our system, we are going to install MySQL 8.0 client, MySQL 8.0 server with the below command:

sudo apt install mysql-client mysql-community-server mysql-server

Hit the y key to start the installation:

Need to get 35.3 MB of archives.
After this operation, 311 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Enter and re-enter root password when prompted

How to install mysql 8.0 on ubuntu 20.04 03

Confirm root password

Secure MySQL Installation

Run the command below to secure MySQL

$ sudo mysql_secure_installation

Press Enter. When prompted for password, provide the root password set above

Enter current password for root (enter for none): <Enter password>
VALIDATE PASSWORD PLUGIN can be used to test passwords 
and improve security. It checks the strength of password 
and allows the users to set only those passwords which are 
secure enough. Would you like to setup VALIDATE PASSWORD plugin? 

Press y|Y for Yes, any other key for No: Y 

There are three levels of password validation policy: 

LOW    Length >= 8 
MEDIUM Length >= 8, numeric, mixed case, and special characters 
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file 

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 
Using existing password for root. 

Estimated strength of the password: 25  
Change the password for root ? ((Press y|Y for Yes, any other key for No) : d


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 
Thanks for using MariaDB!

Check MySQL version

Connect to MySQL to check MySQL installed version. To connect to MySQL, run the below command:

$ mysql -u root -p

Provide the root password set above and once connected, execute the command as below to display MySQL version.

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.23    |
+-----------+
1 row in set (0.00 sec)

Step 4: Create MySQL User (Optional)

While still connected to MySQL, run the following commands to create a user:

CREATE USER 'lorna'@'%' IDENTIFIED BY 'MyStrongPass.';
GRANT ALL PRIVILEGES ON * . * TO 'lorna'@'%'; 
FLUSH PRIVILEGES;
exit

Step 5: Enable MySQL remote access (Optional)

By default, MySQL remote access is disabled. To enable it we need to edit mysqld.cnf file as below:

$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

Look for the line ‘bind_address’ and change as below:

# By default we only accept connections from localhost 
#bind-address   = 127.0.0.1 
bind-address   = 0.0.0.0

Save the file and restart mysql

$ sudo systemctl restart mysql

Allow remote connections through the firewall

sudo ufw allow from <remote_IP_address> to any port 3306
sudo ufw enable

To access the database from a remote machine, run the following command:

$ mysql -u user -h database_server_ip -p

That’s about the installation of mySQL 8.0 on Ubuntu 20.04. Below are more guides that will be f interest to you!

Database Learning videos:

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

LEAVE A REPLY

Please enter your comment!
Please enter your name here