In this Article i will guide you on how to install MySQL 5.7 on Ubuntu 22.04 LTS using command line. This guide aims to provide a comprehensive walkthrough of the installation process, along with helpful tips and best practices to ensure that the installation is successful. So let’s dive in and get started!

Step #1: Remove Mysql if Already Installed

you can use the following commands to remove the mysql if you have already installed on your system

sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*Code language: JavaScript (javascript)

Remove mysql directories:

sudo rm -rf /etc/mysql /var/lib/mysqlCode language: JavaScript (javascript)

To Autoremove, Use Command:

sudo apt-get autoremoveCode language: JavaScript (javascript)

To autoclean, Use Command:

sudo apt-get autocleanCode language: JavaScript (javascript)

Remove database config:

sudo apt-get remove dbconfig-mysqlCode language: JavaScript (javascript)

Step #2: Add MySQL APT Repository

To select the installation repository, we must download and install the packages listed below.

Update System Packages:

sudo apt update

Download the repository using the below command:

wget language: JavaScript (javascript)

Install repository using below command:

sudo dpkg -i mysql-apt-config_0.8.12-1_all.debCode language: CSS (css)

Choose the first 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 option Ok and click OK

Step #3: Update MySQL Repository:

Update your system package again:

sudo apt-get updateCode language: JavaScript (javascript)

Search for MySQL 5,7 using below command:

sudo apt-cache policy mysql-server

Step #4: Install MySQL 5.7

Create conf.d Folder:

sudo mkdir -p /etc/mysql/conf.d

Install MySQL Client:

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

Install MySQL Community:

sudo apt install -f mysql-community-server=5.7.41-1ubuntu18.04

Install MySQL Server:

sudo apt install -f mysql-server=5.7.41-1ubuntu18.04

The installation of MySQL Server on your server has been completed successfully.

Step #5: Check MySQL 5.7 version

To verify the installed version, use the command below.

mysql --version

To log in to MySQL 5.7 Server use command:

sudo mysql

Step #6: Secure MySQL 5.7 Installation

Run the following commands to Secure MySQL:

sudo mysql_secure_installation


This article covered the steps for installing MySQL 5.7 on a system running Ubuntu 22.04 LTS. You should now have a fully functional MySQL 5.7 installation on your Ubuntu 22.04 LTS system. Remember to always follow best practices for security and configuration when using any database management system in production environments.

You can follow steps from video I have posted on my youtube channel Code Sagar.

Official Documentation: