28

I am trying to install MySQL 5.7 on a fresh Ubuntu 20.04 installation. I followed Kulfy's steps in this post to install MySQL 5.7 on Ubuntu 20.04. I was able to install mysql-client, but not mysql-server.

The output of

apt-cache policy mysql-server

is

mysql-server:
  Installed: (none)
  Candidate: 8.0.19-0ubuntu5
  Version table:
     8.0.19-0ubuntu5 500
        500 http://ro.archive.ubuntu.com/ubuntu focal/main amd64 Packages
        500 http://ro.archive.ubuntu.com/ubuntu focal/main i386 Packages
     5.7.30-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
     5.7.29-0ubuntu0.18.04.1 500
        500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages

I used the following command to install mysql-server.

sudo apt install mysql-server=5.7.29-0ubuntu0.18.04.1

The output of the above command is:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
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-server : Depends: mysql-server-5.7 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

I also tried the suggestions in this post and also this one (what I thought could work).

Can you please point me in the right direction?

Thank you!

8 Answers8

33

I managed to make it work! I am not an experienced Linux user, therefore please feel free to comment/edit/improve my answer. As you will see, I don't understand why some things worked and some didn't...

So, I installed mysql-apt-config as a helper. This commented out all entries in /etc/apt/sources.list.d/mysql.list (created according to Kulfy's answer in this post)

This article also helped.

wget http://repo.mysql.com/mysql-apt-config_0.8.10-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

Run the command bellow and select MySQL 5.7 from the list:

sudo dpkg-reconfigure mysql-apt-config
sudo apt update
sudo apt-cache policy mysql-server

I don't know why, but without the following, it gave an error while installing mysql-community-server and failed.

sudo mkdir /etc/mysql/conf.d

Install the components in this order. Otherwise errors similar to the ones in my original question, are displayed. Basically, I tried installing mysql-server - it failed requesting mysql-community-server. I tried installing the later, it failed again, requesting mysql-client. I tried to install this one, and it worked. Then I traced my steps backwards - installed mysql-community-server and then mysql-server. It worked with no errors.

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

I used the following to secure the MySQL installation sudo mysql_secure_installation

Prevent upgrading to MySQL 8 - thanks to NSwanson7 in this post

sudo nano /etc/apt/preferences.d/mysql

Add the following content in the above created file.

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

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

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

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

Package: mysql-apt-config
Pin: version 0.8.10-1
Pin-Priority: 1001

Hope this helps!

Kulfy
  • 18,154
9

I followed this answer and it works.
First I removed mysql from my pc remove Mysql

Then in download section I choose
enter image description here

And generally I follow the errors.
I also install
sudo apt-get install libaio1
where the error said that need that.


UPDATE 31/05/2020 I think the order is :

sudo dpkg -i mysql-common_5.7.30-1ubuntu18.04_amd64.deb 
sudo dpkg -i libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqlclient-dev_5.7.30-1ubuntu18.04_amd64.deb  
sudo dpkg -i libmysqld-dev_5.7.30-1ubuntu18.04_amd64.deb     
sudo dpkg -i mysql-community-source_5.7.30-1ubuntu18.04_amd64.deb  
sudo apt-get install libaio1
sudo apt install libmecab2
sudo dpkg -i mysql-community-client_5.7.30-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-client_5.7.30-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-community-server_5.7.30-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-server_5.7.30-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-community-test_5.7.30-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-testsuite_5.7.30-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb
tsotzolas
  • 191
4

After a lot of struggle I've managed to install and use it in the following way,

  1. From mysql download archive, download generic 5.7, it's best if you first navigate to /usr/local/ so

    sudo su  
    cd /usr/local  
    wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
    
  2. then follow official tutorial from https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

shell> groupadd mysql  
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
shell> bin/mysqld --initialize --user=mysql
shell> bin/mysql_ssl_rsa_setup
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
  1. If you have followed above tutorial, then your mysql base dir is /usr/local/mysql/ and it would seek .cnf files there, so if you need stuff like sockets or anything else, you can put my.cnf in /usr/local/mysql/ and any regular directives there, for example:

    [mysqld]
    #
    # * Basic Settings
    #
    user            = mysql
    socket          = /usr/local/mysql/data/mysqld.sock
    
  2. After installation, don't forget to login and change root pass, because otherwise mysql won't work properly!

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
    

Troubleshooting:
If you get some missing library messages, try installing:

apt install libncurses5 libaio1 libmecab2
3

This worked for me:

wget https://repo.mysql.com//mysql-apt-config_0.8.12-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb

Select Bionic, change to mysql 5.7

sudo apt update
sudo apt install mysql-client=5.7.*-1ubuntu18.04
sudo apt install mysql-community-server=5.7.*-1ubuntu18.04
sudo apt install mysql-server=5.7.*-1ubuntu18.04
1

Best is to use dockers. To downgrade is a nightmare. I wrote short tut how to install Docker container with MySQL 5.7 in ubuntu 20.04 https://assen.xyz/easy-way-to-deploy-mysql-5-7-container-in-ubuntu-20-04/

My xp with downgrading: as @tsotzolas said to use this to clear the v 8.0 installation How do I uninstall MySQL?

But this will clear your users, passwords ... so !! backup!! first, if you made an upgrade.

Then followed these steps https://marabesi.com/mysql/2019/12/23/mysql-5.7-on-ubuntu-19.html

This worked for me in Kubuntu 19.10 and 20.04

AssyK
  • 126
1

For newer version (example from Dockerfile based on ubuntu 20.04):

RUN wget http://repo.mysql.com/mysql-apt-config_0.8.16-1_all.deb \
    && echo mysql-apt-config    mysql-apt-config/repo-codename  select  bionic | debconf-set-selections \
    && echo mysql-apt-config    mysql-apt-config/repo-distro    select  ubuntu | debconf-set-selections \
    && echo mysql-apt-config    mysql-apt-config/select-server  select  mysql-5.7 | debconf-set-selections \
    && echo mysql-apt-config    mysql-apt-config/select-product select  Ok | debconf-set-selections \
    && dpkg -i mysql-apt-config_0.8.16-1_all.deb \
    && apt-get update && apt-get install -y mysql-client=5.7.32-1ubuntu18.04
nex2hex
  • 11
0

I use next file for prevent upgrading:

sudo nano /etc/apt/preferences.d/mysql
Package: libmysqlclient-dev
Pin: version 5.7.30-0ubuntu0.18.04.1
Pin-Priority: 1001

Package: libmysqlclient20 Pin: version 5.7.30-0ubuntu0.18.04.1 Pin-Priority: 1001

Package: libmysqld-dev Pin: version 5.7.30-0ubuntu0.18.04.1 Pin-Priority: 1001

Package: mysql-server Pin: version 5.7.30-0ubuntu0.18.04.1 Pin-Priority: 1001

Package: mysql-client Pin: version 5.7.30-0ubuntu0.18.04.1 Pin-Priority: 1001

Package: mysql-community-server Pin: version 5.7.30-0ubuntu0.18.04.1 Pin-Priority: 1001

Package: mysql-community-client Pin: version 5.7.30-0ubuntu0.18.04.1 Pin-Priority: 1001

Package: mysql-common Pin: version 5.7.30-0ubuntu0.18.04.1 Pin-Priority: 1001

Package: mysql-apt-config Pin: version 0.8.10-1 Pin-Priority: 1001

ormus
  • 1
0

WARNING: This installes 18.04 packages on 22.04.

For an unattended install of the latest and final released mysql deb packages, namely version 5.7.42 on ubuntu 22.04, do this:

#!/bin/bash
set -e

Pre-configure root password

export DEBIAN_FRONTEND=noninteractive ROOT_PASSWORD="your_password_here" debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password $ROOT_PASSWORD" debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password $ROOT_PASSWORD"

mkdir -p /tmp/mysql-install cd /tmp/mysql-install

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_5.7.42-1ubuntu18.04_amd64.deb-bundle.tar

tar xf mysql-server_5.7.42-1ubuntu18.04_amd64.deb-bundle.tar

apt install -y
./mysql-common_5.7.42-1ubuntu18.04_amd64.deb
./libmysqlclient20_5.7.42-1ubuntu18.04_amd64.deb
./mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb
./mysql-client_5.7.42-1ubuntu18.04_amd64.deb
./mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb
./mysql-server_5.7.42-1ubuntu18.04_amd64.deb
./libmysqlclient-dev_5.7.42-1ubuntu18.04_amd64.deb

cd - rm -rf /tmp/mysql-install

Change ROOT_PASSWORD.

For Python MySQL and GDAL support:

apt install -y python3-dev build-essential gdal-bin libgdal-dev

Upgrade existing pypi mysqlclient package like so:

pip uninstall -y mysqlclient
pip install --no-binary mysqlclient mysqlclient