You are on page 1of 6

22/1/2021 How To Install MySQL 5.7 on Ubuntu 20.

04 | ComputingForGeeks

How To Install MySQL 5.7 on Ubuntu 20.04


By Lorna Chepkoech - December 15, 2020

You can support us by downloading this article as PDF from the Link below.

 Download the guide as PDF

In our guide today, we are looking at how to install MySQL 5.7 on Ubuntu 20.04
(Focal Fossa) Server. 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 5.7 on Ubuntu 20.04 (Focal Fossa)

The below steps describe how to install and con gure MySQL 5.7 on Ubuntu
20.04. It start with adding APT repository with packages for MySQL then dives to
the actual package installations and con gurations.

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:

sudo apt update


sudo apt install wget -y
wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb

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

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

In the prompt, choose Ubuntu Bionic and click Ok

https://computingforgeeks.com/how-to-install-mysql-on-ubuntu-focal/ 1/6
22/1/2021 How To Install MySQL 5.7 on Ubuntu 20.04 | ComputingForGeeks

The next prompt shows MySQL 8.0 chosen by default. Choose the rst option
and click OK

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

The next prompt selects MySQL5.7 by default. Choose the last otpion Ok and
click OK

Step 2: Update MySQL Repository on Ubuntu

Run the below command to update your system packages

sudo apt-get update

Now search for MySQL 5,7 using apt-cache as shown below:

$ sudo apt-cache policy mysql-server


mysql-server:
 Installed: (none)
 Candidate: 8.0.21-0ubuntu0.20.04.4
 Version table:
    8.0.21-0ubuntu0.20.04.4 500
       500 http://ke.archive.ubuntu.com/ubuntu focal-updates/main
amd64 Packages
       500 http://ke.archive.ubuntu.com/ubuntu focal-
security/main amd64 Packages
    8.0.19-0ubuntu5 500
       500 http://ke.archive.ubuntu.com/ubuntu focal/main amd64
Packages
    5.7.31-1ubuntu18.04 500

https://computingforgeeks.com/how-to-install-mysql-on-ubuntu-focal/ 2/6
22/1/2021 How To Install MySQL 5.7 on Ubuntu 20.04 | ComputingForGeeks

       500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7


amd64 Packages

As you can see MySQl 5.7.31-1ubuntu18.04 is appearing in the list.

Step 3: Install MySQL 5.7 on Ubuntu 20.04 Linux machine

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

sudo apt install -f mysql-client=5.7.32-1ubuntu18.04 mysql-


community-server=5.7.32-1ubuntu18.04 mysql-server=5.7.32-
1ubuntu18.04

Hit the y key to start installation of MySQL 5.7 on Ubuntu 20.04 Linux.

Reading package lists... Done


Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libgdbm-compat4 libmecab2 libperl5.30 libtinfo5 mysql-common
mysql-community-client perl perl-modules-5.30
Suggested packages:
perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl
make libb-debug-perl liblocale-codes-perl
The following NEW packages will be installed:
libgdbm-compat4 libmecab2 libperl5.30 libtinfo5 mysql-client
mysql-common mysql-community-client mysql-community-server mysql-
server perl perl-modules-5.30
0 upgraded, 11 newly installed, 0 to remove and 35 not upgraded.
Need to get 58.1 MB of archives.
After this operation, 361 MB of additional disk space will be
used.
Do you want to continue? [Y/n] y

Enter and re-enter root password when prompted

Step 3: Secure MySQL 5.7 Installation on Ubuntu 20.04

Run the command below to secure MySQL

https://computingforgeeks.com/how-to-install-mysql-on-ubuntu-focal/ 3/6
22/1/2021 How To Install MySQL 5.7 on Ubuntu 20.04 | ComputingForGeeks

$ sudo mysql_secure_installation

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

Answer the prompts as below:

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                 

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.

To con rm the installed version, rst, connect to MySQL with the set root
password.

$ mysql -u root -p

Run the below command to display version

https://computingforgeeks.com/how-to-install-mysql-on-ubuntu-focal/ 4/6
22/1/2021 How To Install MySQL 5.7 on Ubuntu 20.04 | ComputingForGeeks

$ SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.31    |
+-----------+
1 row in set (0.00 sec)

Step 4: Create MySQL User (Optional, testing only)

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

CREATE USER 'user'@'%' IDENTIFIED BY 'MyStrongPass.';


GRANT ALL PRIVILEGES ON * . * TO 'user'@'%';
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 le 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 le and restart mysql

$ sudo systemctl restart mysql

Allow remote connections through the rewall

$ 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

You have successfully installed MySQL 5.7 on Ubuntu 20.04. Check more
interesting Linux guides below:

https://computingforgeeks.com/how-to-install-mysql-on-ubuntu-focal/ 5/6
22/1/2021 How To Install MySQL 5.7 on Ubuntu 20.04 | ComputingForGeeks

Install MySQL 5.7 on CentOS 8/ RHEL 8 Linux

How to install MySQL 8.0 on Kali Linux

How to install MySQL 5.7 on Fedora

How to install MariaDB on Ubuntu

How to install MongoDB 4 on Ubuntu

You can support us by downloading this article as PDF from the Link below.

 Download the guide as PDF

Lorna Chepkoech

https://computingforgeeks.com/how-to-install-mysql-on-ubuntu-focal/ 6/6

You might also like