MySQL 5.7 on Ubuntu 19.04 and 19.10

Ubuntu 19.04/19.10 as default comes with MySQL 8.0 as it’s default version to work with. Projects that need to use a 5.* version might run into problems in the downgrade process. This post aims to guide the installation of MySQL 5.7 on ubuntu 19.04 and ubuntu 19.10.

After trying to set up MySQL following different sources [1] [2] and fail over everyone, an alternative might be the installation via .deb packages through the official MySQL website, which is explored in detail here. Also, another approach is offered using docker instead of setting up everything from scratch.

Set up

For this approach two assumptions take place, named:

  1. Ubuntu 19 is up and running
  2. Expertise handling commands via terminal (shell)

Lastly, if previous tries to install mysql 5.7 on ubuntu have been done, follow the checklist:

  1. Remove any MySQL installation via apt-get with the command: sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
  2. Remove old MySQL configuration from /etc/mysql with the command: sudo rm -rf /etc/mysql
  3. Keep the apt in a clean state with the command sudo apt-get update --fix-missing

Before installation check list

Ubuntu 19 comes with MySQL 8 as the default version to be installed, to double check that run the following command in the command line sudo apt list | grep mysql-server, the output should display the MySQL version current in use by apt.

mysql-server-8.0/eoan-updates,eoan-security 8.0.18-0ubuntu0.19.10.1 amd64
mysql-server-core-8.0/eoan-updates,eoan-security 8.0.18-0ubuntu0.19.10.1 amd64
mysql-server/eoan-updates,eoan-security 8.0.18-0ubuntu0.19.10.1 all

As expected, the version is 8. Even though previous references have shown how to change the MySQL via apt [1] [2] in early versions of ubuntu, this approach in my experienced was not effective on ubuntu 19.*.

The explored solution might work on docker containers based on ubuntu 19.* as well.

Installing MySQL via .deb files

The first step is to download MySQL 5.7 from MySQL website [3], chose the ubuntu version and hit the download button, in the next phase hit “No thanks, just start my download”. It should take a few minutes to download the entire package.

Disclaimer: this installation process requires a GUI, for terminal only installations use the direct download solution to download the .tar file:

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-server_5.7.28-1ubuntu19.04_amd64.deb-bundle.tar

Once the download has been completed, the .tar file should be available in the downloads folder (or in the folder where the wget was executed), for any standard browser installation the folder will be ~/Downloads. - For now on this is the path referred, for custom directories replace ~/Downloads with the appropriated path.

In the terminal change the directory to where the downloaded file is located, with the command:

cd ~/Downloads

Once in the folder, unpack all the files with the tar [4] command:

tar -xvf mysql-server_5.7.28-1ubuntu19.04_amd64.deb-bundle.tar

Once the command has run, the extracted files list should contain the MySQL 5.7.* deb files:

mysql-client_5.7.28-1ubuntu19.04_amd64.deb
mysql-common_5.7.28-1ubuntu19.04_amd64.deb
mysql-community-client_5.7.28-1ubuntu19.04_amd64.deb
mysql-community-server_5.7.28-1ubuntu19.04_amd64.deb
mysql-community-source_5.7.28-1ubuntu19.04_amd64.deb
mysql-server_5.7.28-1ubuntu19.04_amd64.deb
mysql-testsuite_5.7.28-1ubuntu19.04_amd64.deb
mysql-community-test_5.7.28-1ubuntu19.04_amd64.deb

To prevent potential issues, the test packages can be removed as they aren’t required to install or run MySQL server. To remove those files run the following command:

rm -rf mysql-testsuite_5.7.28-1ubuntu19.04_amd64.deb mysql-community-test_5.7.28-1ubuntu19.04_amd64.deb

The final command to execute the installation is:

dpkg -i mysql-*.deb

The command will select all files that start with mysql- that has .deb extension and will start the installation process.

Once the command has completed execution, check MySQL server status with the following command:

/etc/init.d/mysql status

Which in turn, should output:

 * MySQL Community Server 5.7.28 is started

Usually the MySQL service starts by default after the installation - if this is not the case the command /etc/init.d/mysql start can be used to start the service.

Troubleshooting

Errors related due the lack of dependent packages, usually can be fixed running the command sudo apt-get update --fix-missing after the error message. Ubuntu will try to install the missing dependencies automatically.

EDIT: May 19 2020

Another approach to avoid the need to install MySQL on Ubuntu 19.04 or 19.10 is to use the docker image [5] - This solution applies to users that have the minimum understanding of docker.

The following command, runs MySQL 5.7 on por 3306, without the need to install it:

docker run --name mysql-5-7 --restart always -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.7

Docker will create a MySQL container running on port 3306 with the root user and the secret password.

References

  1. [1]F. O. S. S. TechNix, “How To Install MySQL 5.7 on Ubuntu 16.04,” 2019 [Online]. Available at: https://www.fosstechnix.com/install-mysql5-on-ubuntu. [Accessed: 26-Dec-2019]
  2. [2]R. Kumar, “How to Install MySQL 5.7 on Ubuntu 16.04 LTS,” 2019 [Online]. Available at: https://tecadmin.net/install-mysql-5-on-ubuntu. [Accessed: 26-Dec-2019]
  3. [3]O. C. and/or its affiliates, “MySQL Community Downloads,” 2019 [Online]. Available at: https://dev.mysql.com/downloads/mysql/5.7.html. [Accessed: 26-Dec-2019]
  4. [4]N/A, “How to open a tar file in Unix or Linux,” 2019 [Online]. Available at: https://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux. [Accessed: 26-Dec-2019]
  5. [5]Dockerhub, “MySQL Docker official image,” 2020 [Online]. Available at: https://hub.docker.com/_/mysql. [Accessed: 19-May-2020]