How to Install the Latest MySQL 8 on Ubuntu 20.04

MySQL is a relational database management system based on SQL (Structured Query Language). It is one of the most widely used database software for several well-known applications that utilize it. MySQL is used for data warehousing, e-commerce, and logging applications, but its most used feature is a web database storage and management.

Ubuntu 20.04 comes with MySQL in its repository, and however, as many know, Ubuntu LTS releases only provided security updates for its releases to keep its stable build essentially stable. This has great benefits but some drawbacks; in the tutorial, you will learn how to install MySQL 8 for Ubuntu 20.04.

Advertisement

Prerequisites

  • Recommended OS: Ubuntu 20.04 – optional (Ubuntu 21.04)
  • User account: A user account with sudo or root access.
  • Required Packages: wget

Updating Operating System

Update your Ubuntu 20.04 operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade

Import the MySQL Repository

To install the latest version of MySQL, you will need to download and install the MySQL APT .deb repository package that will configure and install the MySQL software repositories on your system. To get the latest link to replace in the example below, visit the APT repository download page on MySQL.

Use the following command below to download to your TMP folder:

cd /tmp
wget https://dev.mysql.com/get/mysql-apt-config_0.8.19-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.19-1_all.deb

During the MySQL repository installation, you will see the following pop-up windows:

First, you will be asked to confirm what version of MySQL you want to install; for now, it is set up correctly for the latest version, so using the arrow keys, scroll down and select ok to continue:

Select OK to proceed with the installation:

You will see a second window advising you that you have no MySQL server configured on your system for fresh installs. Select the package that best suits your needs which for most cases be the first choice mysql-8.0.

Example:

How to Install the Latest MySQL 8 on Ubuntu 20.04

Once done, you will get the following message back in your terminal:

OK

To reflect the new repository, use the apt update command:

sudo apt update
Advertisement

Install MySQL 8

Now that you have completed the import of the repository for MySQL, execute the command to install as follows:

sudo apt install mysql-server

Examples of dependencies that will also be installed:

How to Install the Latest MySQL 8 on Ubuntu 20.04

Type Y, then press enter key to proceed with the installation.

During the installation, a new popup will appear, prompting you to enter the database root password. Make sure this is secure and recorded. Once entered, press the enter key or press tab key to select the <Ok> and hit enter to proceed with the installation:

Example:

How to Install the Latest MySQL 8 on Ubuntu 20.04

Note, you will be prompted to re-enter the root password a second time to confirm.

Next, another popup will appear for you to read about the new authentication system.

Next, set the default selection for MySQL for authentication plugin as below:

How to Install the Latest MySQL 8 on Ubuntu 20.04

Lastly, you will be queried about which encryption to use. It is recommended to use the Strong Password Encryption:

Example:

How to Install the Latest MySQL 8 on Ubuntu 20.04

The installation should finish up after this point. To confirm it has been successfully installed, run the following apt policy command, which will also confirm the current version and build of the MySQL database server:

apt policy mysql-server

Example output:

How to Install the Latest MySQL 8 on Ubuntu 20.04
Advertisement

Check MySQL 8 server status

The installer will automatically start your MySQL service by default and configure itself to auto-start on system boot. To verify your MySQL service is operational after the installation, type the following systemctl command:

systemctl status mysql 

Example output:

How to Install the Latest MySQL 8 on Ubuntu 20.04

To stop the MySQL service:

sudo systemctl stop mysql

To start the MySQL service:

sudo systemctl start mysql

To disable the MySQL service on system boot:

sudo systemctl disable mysql

To enable the MySQL service on system boot:

sudo systemctl enable mysql

To restart the MySQL service:

sudo systemctl restart mysql

Secure MySQL 8 with Security Script

When installing MySQL fresh, default settings are considered weak by most standards and cause concern for potentially allowing intrusion or exploiting hackers. A solution is to run the installation security script that comes with the MySQL installation.

First, use the following command to launch the (mysql_secure_installation):

sudo mysql_secure_installation

You will be prompted to enter your root password, and then you will see a question about VALIDATE PASSWORD COMPONENT; this is to set password complexity checks; for most, the default is fine.

Next, follow below:

  • Setting the password for root accounts.
  • Removing root accounts that are accessible from outside the local host.
  • Removing anonymous-user accounts.
  • Removing the test database, which by default can be accessed by anonymous users.

Note, you use (Y) to remove everything. Also, if you like, you can reset your root password by creating a new one; you can skip this if you like as you already set it during the initial installation with the pop-up windows.

Example:

How to Install the Latest MySQL 8 on Ubuntu 20.04

Login to MySQL 8 instance

Now that you have completed the post-installation installation security script, login into your MySQL database can be done using the following:

sudo mysql -u root -p

You will be prompted to enter the root password that you set in either the installation setup or post-installation security script. Once inside the MySQL service instance, you can execute the following command as a test to see it in operation.

Type the following SHOW DATABASE command:

SHOW DATABASES;

For those new to MySQL, all commands must end with “;

Example:

How to Install the Latest MySQL 8 on Ubuntu 20.04

To exit the terminal, type the following exit command:

EXIT;

Uninstall MySQL 8

If you no longer wish to use the MySQL database and want to remove it in full, execute the following command:

sudo apt autoremove mysql-server

Example output:

How to Install the Latest MySQL 8 on Ubuntu 20.04

Type Y, then press enter key to proceed with the uninstallation.

Comments and Conclusion

In the tutorial, you have learned how to install the latest MySQL 8. Overall, MySQL 8 has better performance for reading/write workloads, IO-bound workloads, and high contention workloads. In addition, along with options to optimize for specific workloads on specific hardware by mapping user threads to CPUs, to name a few of the new features. Users on older versions of MySQL should consider upgrading, as the performance gains are definitely worth it.

Subscribe
Notify of
1 Comment
Inline Feedbacks
View all comments
Volodymyr
Guest
Thursday, January 27, 2022 5:46 am

у меня без публичного ключа толком не ставится.
поэтому перед

sudo apt install mysql-server

дал команду

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x467B942D3A79BD29

Вроде теперь всё в порядке ))

adplus-dvertising
1
0
Would love your thoughts, please comment.x
()
x