Install MySQL 5.7 server and client on Ubuntu 22.04 LTS Linux

The current MySQL server version to install through the Ubuntu 22.04 repository is 8.0, however, for some reason, if you need MySQL 5.7 then in this tutorial we learn how to install that.

MySQL is not some unknown software platform, it has been used widely to store data in various web applications. It is a cross-platform database system and therefore can be installed on most of the popular operating systems, including Ubuntu Linux.

Well, the version of MySQL 5,7 is not supported anymore that’s the reason it is not available from the base repository of the latest Linux. However, still, users of the Ubuntu 22.04 LTS (Long Term Support) version can install MySQL 5.7 by adding its repo manually.

Let’s see how to install MySQL 5.7 on Ubuntu 22.04 LTS using this step-by-step guide …

1. Update Ubuntu 22.04

It is important to start with updating our system because this not only helps Ubuntu to get security packages but also refreshes the package index cache of the APT package manager.

sudo apt update && sudo apt upgrade

2. Installing necessary packages

There are a few packages we need on our system for installing the MySQL 5.7 server on Ubuntu 22.04, therefore first configure them using the below-given command.

sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https  wget

3. Configure MySQL 5.7 Repository

As we know by default Ubuntu 22.04 will not let us install the MySQL 5.7 Database version, therefore, we manually need to configure an old repository available for it.

  1. First, download the Debian package to configure the MySQL 5.7 repository using the given command
  1. Install the downloaded Deb file from using the DPKG package management tool.
sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
  1. As we are on the Ubuntu jammy which is not supported system by MySQL 5.7, hence we have to select the Ubuntu version that supports this old version of Oracle Database. So, choose the Ubuntu bionic using the arrow keys and hit the Enter key.
Select unsupported Ubuntu version for MySQL 5.7
  1. You will have a “Configure mysql-apt-config” display in your Terminal. Select the first option “MySQL Server & Cluster (Currently Select: mysql-8.0” and hit the Enter key.
Select MySQL product to configure
  1. You will see MySQL-5.7 in the product list that we want on Ubuntu Jammy, so select that and press the Enter key to move forward.
MySQL 5.7 repository on Ubuntu 22.04 add
  1. Finally, we have done all the settings for the MySQL 5.7 repository to add to your system. Simply with the help of the arrow keys select OK and press Enter key.
установка mysql 5.7 ubuntu 22.04

4. Add GPG key for MySQL 5.7 on Ubuntu 22.04

Well, as you add the repository of MySQL 5.7, a warning apt-key is deprecated will appear because Ubuntu 22.04 stores GPG keys in ‘trusted.gpg.d’ that are used only for their respective repository’s packages to install or update.


Selecting previously unselected package mysql-apt-config.
(Reading database ... 231362 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.12-1_all.deb ...
Unpacking mysql-apt-config (0.8.12-1) ...
Setting up mysql-apt-config (0.8.12-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).

So, to remove this warning manually add the GPG key for MySQL 5.7 in Ubuntu 22.04’s trusted.gpg.d directory.

gpg --keyserver --recv-keys 467B942D3A79BD29
gpg --export --armor 467B942D3A79BD29 | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/mysql.5.7-key.gpg

Run system update:

sudo apt update
Adding GPG key to Ubuntu 22.04

5. Installing MySQL 5.7 in Ubuntu 22.04 Server

Finally, we have configured the repository properly and now we can download the MySQL 5.7 server and client packages from it using the default APT package manager of Ubuntu.

Note: If you have already MariaDB installed then first completely remove it.

Here is the command to follow:

sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*

We are using -f flag to forcefully install version 5,7 otherwise due to priority, the system keeps preferring 8.0 and through an error.

Installing MySQL 5.7 on Ubuntu 22.04

While installing, the process will ask you to set a root password for the MySQL Database server. Set some strong password…

mysql community server password for root

6. Verifying service status

To ensure MySQL service is running in the background once the installation process is completed, check it.

systemctl status mysql --no-pager -l
Verifying the MySQL service status

If it is not active then to start it, we can use:

sudo systemctl start mysql

Whereas, in the future, if you need to stop or restart the MYSQL server, the commands are:

For restarting the Oracle MYSQL Database server

sudo systemctl restart mysql

For Stopping:

sudo systemctl stop mysql

7. Running security script

To remove the anonymous users, disallow root login remotely, remove the test database, and perform other settings to secure your Database server use the given command.

sudo mysql_secure_installation

Follow the text-based wizard that appeared on your terminal to perform the setting.

8. Checking MySQL version 5.7

So, far we have done everything we need to configure and use MySQL version 5.7 on Ubuntu 22.04. To confirm, what version of it we have on our system, here is the simple command:

mysql --version
Checking the MySQL version 5.7

9. Connecting to MySQL

To connect and start creating ‘Databases and users’, first log in:

sudo mysql -u root -p 

After that to create a user and password for that, you can use this syntax:

 CREATE USER 'linuxshout'@'%' IDENTIFIED BY 'shout123';

Replace linuxshout with the user you want to create and shout123 with a password for it.

10. Uninstallation of MySQL 5.7

If you don’t require MySQL 5.7 on Ubuntu 22,.04 then to remove it completely from your Linux system, here is the command to run:

sudo apt autoremove --purge mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*

To remove the Repository and GPG key as well:

sudo rm /etc/apt/sources.list.d/mysql.list /etc/apt/trusted.gpg.d/mysql.5.7-key.gpg

In this way, we can perform the installation of the old MySQL 5.7 database server on Ubuntu 22.04 LTS Linux easily but by following the steps carefully and ensuring that all dependencies are met; to have a fully functional MySQL database server.

Other Articles:

3 thoughts on “Install MySQL 5.7 server and client on Ubuntu 22.04 LTS Linux”

  1. Thank you for this. Every other instruction uses apt key, which no longer works. I am getting this error, however. Any ideas?

    Ubuntu 22.04.3 LTS

    root@myserver:~# apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
    Reading package lists… Done
    Building dependency tree… Done
    Reading state information… Done
    Selected version ‘5.7.42-1ubuntu18.04’ ( [amd64]) for ‘mysql-client’
    Selected version ‘5.7.42-1ubuntu18.04’ ( [amd64]) for ‘mysql-community-server’
    Selected version ‘5.7.42-1ubuntu18.04’ ( [amd64]) for ‘mysql-server’
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    mysql-client-core-8.0 : Conflicts: virtual-mysql-client-core
    E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.