Is it possible to install MySQL Server 5.7 on Ubuntu 19.10?

Solution 1:

MySQL server 5.7 isn't available in the repositories of Eoan Ermine (19.10) but is available in Bionic Beaver (18.04) from Ubuntu's official repostories as well as MySQL's. You can install MySQL Server 5.7 on Eoan using Bionic's repository.

  1. To use MySQL's repository for Ubuntu 18.04

    • First of all create a new text file with sudo privileges:

      sudo nano /etc/apt/sources.list.d/mysql.list
      
    • Add these lines:

      deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config
      deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
      deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools
      #deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools-preview
      deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
      

      You can comment/uncomment the repository according to the packages required. Save and exit using Ctrl+X followed by Y. Then run

      sudo apt update
      
    • You'll get an error, like

      Err:1 http://repo.mysql.com/apt/ubuntu bionic InRelease                        
        The following signatures couldn't be verified because the public key is not available: NO_PUBKEY <some key value>
      
    • Add this key using

      sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <key value>
      
    • Update and check which version of MySQL 5.7 is currently available

      sudo apt update
      apt-cache policy mysql-server
      

      At the time of writing this answer, 5.7.29-1ubuntu18.04 was available.

    • Install the required MySQL version.

      sudo apt install mysql-server=5.7.29-1ubuntu18.04
      

    Note: For some reasons in my installation APT wasn't installing mysql-client while installing MySQL Server 5.7 which is a dependency of MySQL Community Server which in turn is a dependency of MySQL Server due to which dependency issues occured. To get out of that I needed to install MySQL client using APT first

    sudo apt install mysql-client=5.7.29-1ubuntu18.04
    
  2. To install using Ubuntu's repositories, add Ubuntu 18.04's official repositories, update the cache and instal MySQL 5.7. Fo that run:

    echo "deb http://security.ubuntu.com/ubuntu/ bionic-security restricted main" | sudo tee /etc/apt/sources.list.d/bionic.list
    sudo apt update
    apt-cache policy mysql-server
    sudo apt install mysql-server=5.7.29-0ubuntu0.18.04.1
    

    I'd recommend to delete Bionic's repository after the installation since having repository information of other releases can sometime break the installation. To do that run

    sudo rm /etc/apt/sources.list.d/bionic.list
    

Solution 2:

Adding onto Kulfy's answer. If you want to prevent the package from being updated back to MySQL 8+, create a file named mysql at /etc/apt/preferences.d/.

In that file place the following contents

Package: mysql-server
Pin: version 5.7.29-1ubuntu18.04
Pin-Priority: 1001

Package: mysql-client
Pin: version 5.7.29-1ubuntu18.04
Pin-Priority: 1001

Package: mysql-community-server
Pin: version 5.7.29-1ubuntu18.04
Pin-Priority: 1001

Package: mysql-community-client
Pin: version 5.7.29-1ubuntu18.04
Pin-Priority: 1001

This will prevent apt upgrade from upgrading MySQL back to version 8.

NOTE: The version you use may be different, as of 2/12/2020 the version is 5.7.29-1ubuntu18.04. To get the version run apt list --installed | grep -E 'mysql-(client|server)'.

Solution 3:

Extending on the answers of both Kulfy and NSwanson7, the installation can be fixed to version 5.7.*. No need to specify an exact version.

  1. Pin the version of mysql-client and mysql-server to 5.7*. For this create the file /etc/apt/preferences.d/mysql with content
    Package: mysql-server
    Pin: version 5.7*
    Pin-Priority: 1001
    
    Package: mysql-client
    Pin: version 5.7*
    Pin-Priority: 1001
    
  2. Add repositories from Ubuntu 18.04. For this create file /etc/apt/sources.list.d/mysql.list with content
    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config
    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
    deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools
    deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
    
  3. Update repos and install
    sudo apt update && sudo apt install mysql-client mysql-server
    

or use the below script:

echo "deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config"  | sudo tee /etc/apt/sources.list.d/mysql.list
echo "deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7"  | sudo tee -a /etc/apt/sources.list.d/mysql.list
echo "deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools"  | sudo tee -a /etc/apt/sources.list.d/mysql.list
echo "deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7"  | sudo tee -a /etc/apt/sources.list.d/mysql.list

echo "Package: mysql-server" | sudo tee /etc/apt/preferences.d/mysql
echo "Pin: version 5.7*" | sudo tee -a /etc/apt/preferences.d/mysql
echo "Pin-Priority: 1001" | sudo tee -a /etc/apt/preferences.d/mysql
echo "" | sudo tee -a /etc/apt/preferences.d/mysql
echo "Package: mysql-client" | sudo tee -a /etc/apt/preferences.d/mysql
echo "Pin: version 5.7*" | sudo tee -a /etc/apt/preferences.d/mysql
echo "Pin-Priority: 1001" | sudo tee -a /etc/apt/preferences.d/mysql

sudo apt update
sudo apt -y install mysql-server mysql-client