Install MySQL 5.7 on Ubuntu 20.04
Solution 1
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!
Solution 2
I followed this answer and it works.
First I removed mysql from my pc remove Mysql
Then in download section I choose
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
Solution 3
After a lot of struggle I've managed to install and use it in the following way,
-
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
-
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
-
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
-
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
Solution 4
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
Solution 5
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
Related videos on Youtube
Lucian Ilea
Updated on September 18, 2022Comments
-
Lucian Ilea almost 2 years
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!
-
Kulfy about 4 yearsI 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?
-
Lucian Ilea about 4 yearsI 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... -
Kulfy about 4 yearsActually 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.
-
Lucian Ilea about 4 yearsI did that, as you suggested! Thank you!
-
KolaB almost 4 yearsThanks 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 repo.mysql.com for the latest version of mysql-apt-config
-
-
Kulfy about 4 yearsSo what are the contents of
mysql.list
now? -
Lucian Ilea about 4 yearsI didn't look at it until you asked... But, now it looks identical to what you provided in your post...
-
Lucian Ilea about 4 yearsThank you for your answer! I tried something similar at some point, but I got discouraged by the errors and searched for other solutions. :-)
-
joe92 about 4 yearsHi 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!
-
Lucian Ilea about 4 yearsI'm glad it did! Thank you for your feedback! :-)
-
King Midas almost 4 yearsIf you use this commands, I would suggest to execute also
sudo apt-mark hold mysql-client
,sudo apt-mark hold mysql-community-client
andsudo apt-mark hold mysql-community-server
or will be overriten by mysql 8.0 in the next update. -
steffres almost 4 yearsThe 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: gist.github.com/ahmadhasankhan/48fc9fc9a19807daef1622751a56884b
-
Mubashar Abbas over 3 yearsThat's just perfect.. BTW. i tried this link fosstechnix.com/how-to-install-mysql-5-7-on-ubuntu-20-04-lts before and it didn't work.. Thankyou so much pal.
-
mralexandrelise over 3 yearsInstall 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
-
randomScott about 3 yearsAt 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: digitalocean.com/community/questions/… 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.
-
Jason Kennaly about 2 yearsThis installation order really helped me get the dependencies straightened out.