A Quick Guide on Installing MySQL on Ubuntu

Total: 0 Average: 0

This article will present the step-by-step installation process of the MySQL server on Ubuntu. For demonstration purposes, I created a virtual machine using Oracle VM virtual box and set up Ubuntu 18.04 on the virtual box. I’d recommend you referring to the article Creating a Virtual Machine with Oracle VM Virtual Box for a better understanding of the installing process and creating a virtual machine on Oracle VM virtual box. Also, you may turn to the article How to Install Ubuntu 18.04 for more information about installing Ubuntu 18.04 on the virtual machine.

CodingSight - A Quick Guide on Installing MySQL on Ubuntu

Install MySQL 8.0 on Ubuntu using PuTTY

We are going to use the PuTTY software to connect to Ubuntu Linux. If you don’t have it installed, get the software from the official page

Launch PuTTY, specify the hostname and click Open.

Launch PuTTY, specify the hostname and click Open.

PuTTY prompts for the username and password. Specify these details and hit Enter.

PuTTY prompts for the username and password. Specify these details and hit Enter.

Once we are connected to Linux, connect to the root user by executing the below command:

nisarg@LinuxSQL01:~$ sudo -i
Once we are connected to Linux, connect to the root user by executing the below command

Before installing the MySQL Server, we must update the Ubuntu repository. Execute the following command:

root@LinuxSQL01:~# sudo apt-get update

As soon as the repository is updated, we use the wget command to download the latest package of the MySQL Server from MySQL APT Repository:

root@LinuxSQL01:~# wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb

After we download it, execute the below command to install the MySQL package:

root@LinuxSQL01:~# sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb

The MySQL package configuration wizard opens. On the first screen, you can view the MySQL products list you can install with that wizard – any of the following MySQL servers or components:

  1. MySQL 5.7
  2. MySQL 8.0
  3. MySQL Cluster 7.5
  4. MySQL Cluster 7.6
  5. MySQL Cluster 8.0

If you want to change the current selection of MySQL, hit Enter on the first option:

If you want to change the current selection of MySQL, hit Enter on the first option

View the list of the MySQL Server versions. We want to install MySQL 8.0, so choose mysql-8.0 and hit Enter.

View the list of the MySQL Server versions. We want to install MySQL 8.0, so choose mysql-8.0 and hit Enter

Back to the first screen of the Wizard, select OK by pressing the down the arrow key and hit Enter.

Back to the first screen of the Wizard, select OK by pressing the down the arrow key and hit Enter.

The latest repository of MySQL 8.0 has been installed.

Now, run the following command to update the repositories:

root@LinuxSQL01:~# sudo apt-get update

When the process is complete, run the following command to install MySQL 8.0:

root@LinuxSQL01:~# sudo apt-get install mysql-server

The installer shows the amount of space to be utilized and prompts for confirmation. Press Y and hit Enter.

The installer shows the amount of space to be utilized and prompts for confirmation. Press Y and hit Enter

The installation process continues. On the next screen, the installer prompts to enter the root password. Specify the appropriate password and hit Enter.

On the next screen, the installer prompts to enter the root password. Specify the appropriate password and hit Enter

Proceed to the next screen, re-enter the root password, and hit Enter.

Proceed to the next screen, re-enter the root password, and hit Enter

MySQL 8.0 uses improved SHA256 password authentication. As we are working with MySQL 8.0, we must update the client connectors and other components. More details are provided on the screen of the installer – review them and hit Enter.

MySQL 8.0 uses improved SHA256 password authentication. As we are working with MySQL 8.0, we must update the client connectors and other components. More details are provided on the screen of the installer – review them and hit Enter

Next, you can choose the default authentication method to be used by MySQL 8.0. We are not updating the client components, so choose Use Legacy Authentication Method and hit Enter.

The installation continues.

Next, you can choose the default authentication method to be used by MySQL 8.0. We are not updating the client components, so choose Use Legacy Authentication Method and hit Enter

When the installation completes, you can view the status of the MySQL service by executing the following command:

root@LinuxSQL01:~# service mysql status

Output:

The output of the command to view the status of the MySQL service after installation is completed

As you can see, MySQL services are running. Now, let us connect to MySQL Server and run some queries.

Connect to the MySQL Server

First, we check the MySQL Server version by executing the following command:

root@LinuxSQL01:~# mysql -V

Output:

The output of the query to check the MySQL Server version

Run the following command to connect to MySQL Server:

root@LinuxSQL01:~# mysql -U root -p

The command prompts for the password of the root user. Specify it and hit Enter.

The command prompts for the password of the root user. Specify it and hit Enter.

The connection has been established successfully:

The connection has been established successfully

Let us see the list of the databases – run the following query:

mysql> show databases;

Output:

The output of the query to view the list of the databases

MySQL 8.0 has been installed successfully on Ubuntu 18.04.

Install MySQL 8.0 on Ubuntu using Debian Package manager

To install MySQL 8.0 using the Debian package manager, you must first download the MySQL 8.0 package. Open the MySQL Community Downloads page and select Ubuntu Linux from the drop-down menu. It will display the list of packages. We will install the entire package with all tools.

Click on download opposite to the Ubuntu Linux 20.10 (x86, 64bit), Deb bundle.

Click on download opposite to the Ubuntu Linux 20.10 (x86, 64bit), Deb bundle.

The Oracle web account login page opens. If you have signed up for the oracle account, provide relevant login details and download the package. We are not using any Oracle web account. Thus, click on the start my download link.

Click on the start my download link

The download process begins. Once it is over, we begin the installation.

First, we must extract files from the tar file that contains various Debian packages for installing MySQL client tools and community servers. To do that, right-click on the mysql-server-8.0.23..tar file > Extract.

First, we must extract files from the tar file that contains various Debian packages for installing MySQL client tools and community servers. To do that, right-click on the mysql-server-8.0.23..tar file > Extract.

When the files are extracted, we first install libaio1 library. Execute the following command:

root@LinuxSQL01:~# sudo apt-get install libaio1

Output:

The output of the query to install libaio1 library

As you can see, the package is already installed. Now, preconfigure the MySQL package by executing the following command:

root@LinuxSQL01:~# sudo dpkg-preconfigure /home/nisarg/Downloads/mysql-server_8.0.23-1ubuntu20.10_amd64.deb-bundle/mysql-community-server_*.deb

This way, we start installing MySQL 8.0. The installation steps are like the installation process done by the MySQL APT repository, as described in this article earlier.

Once the installation process completes, you can view MySQL server services by running the following command:

root@LinuxSQL01:~# service mysql status

Output:

The output of the query to view MySQL server services

As you can see, MySQL services are running

Summary

This article explained the step-by-step process of installing MySQL Server 8.0 on Ubuntu Linux. For that, we can use PuTTY or Ubuntu software manager. You choose the method that suits you best, and I hope that it will make your work smoother.

Nisarg Upadhyay

Nisarg Upadhyay

Nisarg is a SQL Server Database Administrator and Microsoft certified professional who has more than 5 years of experience with SQL Server administration and 2 years with Oracle 10g database administration. He has expertise in database design, performance tuning, backup and recovery, HA and DR setup, database migrations and upgrades. He has completed the Bachelors in Information Technology from Ganpat University.