Skip to content

Instantly share code, notes, and snippets.

@thesuhu
Last active September 1, 2022 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thesuhu/d13d252563883fd7c03e7bc719c741aa to your computer and use it in GitHub Desktop.
Save thesuhu/d13d252563883fd7c03e7bc719c741aa to your computer and use it in GitHub Desktop.
How to Install MySQL on Ubuntu

How to Install MySQL on Ubuntu

This tutorial has been tested on Ubuntu 20.04 LTS.

Install latest version

Before install, don't forget to update package index in your server.

sudo apt update

Then install MySQL package.

sudo apt install mysql-server

Wait until the process is complete and then configure it to secure your MySQL server. This step will take you through a series of prompts where you can make some changes like password etc.

sudo mysql_secure_installation

Lastly you can try to login using root user, check version, create other user, databases, tables and etc.

Install specific version

What if we want to install a specific version of mysql? Below is an example of installing mysql version 5.7. First, download MySQL 5.7 repository.

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

After the download is complete, then install the repository.

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

In the prompt, do this:

  • choose Ubuntu Bionic
  • select the MySQL Server & Cluster option
  • choose mysql-5.7 and then select ok

When finished, update the APT repository.

sudo apt update 

if you encounter problems like this:

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29

Do import the missing gpg key.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29

And then re-run apt update

sudo apt update 

Check if the MySQL 5.7 repository was successfully installed.

sudo apt-cache policy mysql-server

if successful, the MySQL 5.7 repository will appear in the list.

mysql-server:
  Installed: (none)
  Candidate: 8.0.30-0ubuntu0.22.04.1
  Version table:
     8.0.30-0ubuntu0.22.04.1 500
        500 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
        500 http://id.archive.ubuntu.com/ubuntu jammy-security/main amd64 Packages
     8.0.28-0ubuntu4 500
        500 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
     5.7.39-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages

Then, it's time to install MySQL 5.7 using apt install.

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

in the process of installing, please set the root password when prompted. Wait until the process is complete and then configure it to secure your MySQL server.

sudo mysql_secure_installation

Enter your root password answer all of the security questions. Lastly you can try to login using root user, check version, create other user, databases, tables and etc.

mysql -u root -p

And then you can check the version. Type this statement:

SELECT VERSION();

You will see the MySQL version like this:

+-----------+
| VERSION() |
+-----------+
| 5.7.39    |
+-----------+
1 row in set (0.00 sec)

All done. If you find it useful please star (⭐) & share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment