Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Install MySQL 5.7 on Ubuntu 20.04

Writer Emily Wong

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 focal/main amd64 Packages 500 focal/main i386 Packages 5.7.30-1ubuntu18.04 500 500 bionic/mysql-5.7 amd64 Packages 5.7.29-0ubuntu0.18.04.1 500 500 bionic-security/main amd64 Packages 500 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!

5

7 Answers

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
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!

7

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
3

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 
  2. then follow official tutorial from

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

This worked for me:

wget
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

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

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

Then followed these steps

This worked for me in Kubuntu 19.10 and 20.04

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

RUN wget \ && 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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy