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!

  • I didn't test things on 20.04. Since you were using 5.7.29-0ubuntu0.18.04.1 as the version string, it was fetching the MySQL present in Ubuntu's bionic repository. Have you tried mysql-server-5.7 instead? – Kulfy Apr 29 '20 at 16:11
  • I couldn't make it work, therefore, at some point in the struggle, I switched to 5.7.30-1ubuntu18.04. I tried mysql-server-5.7 also... – Lucian Ilea May 01 '20 at 11:20
  • Actually you had MySQL as well as Ubuntu's repository for 18.04. Since both have 5.7 in them but different versions so there was a version conflict. Consider removing Ubuntu's security repository for Bionic if you're using Focal. – Kulfy May 01 '20 at 11:33
  • I did that, as you suggested! Thank you! – Lucian Ilea May 01 '20 at 12:01
  • Thanks for this post. Helped to sort out my problem. However, I had a GPG-Key issue due to the version of mysql-apt-config. I also could not install 5.7.30-1ubuntu18.04 as of 16/07/2020. The versions that worked for me were mysql-apt-config_0.8.15-1_all.deb and 5.7.31-1ubuntu18.04. It may be best to checkout http://repo.mysql.com/ for the latest version of mysql-apt-config – KolaB Jul 16 '20 at 20:35

7 Answers7

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
  • 17,696
  • So what are the contents of mysql.list now? – Kulfy Apr 29 '20 at 16:05
  • I didn't look at it until you asked... But, now it looks identical to what you provided in your post... – Lucian Ilea May 01 '20 at 11:17
  • Hi Lucian, thank you for this answer. I also needed MySQL 5.7 on Ubuntu 20.04 for JIRA, since Atlassian STILL haven't introduced support for 8.0 (come on Atlassian, sort yourself out). Your solution worked for me, cheers! – joe92 May 12 '20 at 15:02
  • I'm glad it did! Thank you for your feedback! :-) – Lucian Ilea May 13 '20 at 16:25
  • That's just perfect.. BTW. i tried this link https://www.fosstechnix.com/how-to-install-mysql-5-7-on-ubuntu-20-04-lts/ before and it didn't work.. Thankyou so much pal. – Mubashar Abbas Oct 20 '20 at 15:16
  • Install mysql-apt-config then doing the pinning then install mysql-community-server without -f seems to work fine for me thanks for pointing me to the right direction – mralexandrelise Dec 23 '20 at 00:35
  • At one point I got stuck with it not wanting to install one of the packages, probably because prior attempts mucked something up in the apt configuration. An answer here: https://www.digitalocean.com/community/questions/mysql-installation-error-dpkg-error-processing-package-mysql-server-5-5-configure lead me to purging all the previously attempted packages and doing a dist-upgrade, which seemed to help. I also deleted the prior /etc/mysql and /var/lib/mysql directories. After that, the above procedure worked for me. – randomScott May 06 '21 at 19:27
  • When i tried the same in Ubuntu 18 and 20 , the configuring mysql-apt-config questions are looping and never ends :( what to do ? – jpk Jan 17 '23 at 05:36
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
  • 1
    Thank you for your answer! I tried something similar at some point, but I got discouraged by the errors and searched for other solutions. :-) – Lucian Ilea May 01 '20 at 11:24
  • The official binaries were for me the cleanest way to set things up. However with the official tutorial I did not get mysql server 5.5.62 running on UbuntuServer 20.04. What helped me was this gist here: https://gist.github.com/ahmadhasankhan/48fc9fc9a19807daef1622751a56884b – steffres Jul 28 '20 at 10:42
  • This installation order really helped me get the dependencies straightened out. – Jason Kennaly Apr 22 '22 at 18:17
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
  • 3
    If you use this commands, I would suggest to execute also sudo apt-mark hold mysql-client, sudo apt-mark hold mysql-community-client and sudo apt-mark hold mysql-community-server or will be overriten by mysql 8.0 in the next update. – King Midas Jul 16 '20 at 09:31
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
  • 1