How can I properly downgrade from MySQL 8 to 5.7 on Ubuntu 20.04

Posted November 25, 2020 22.7k views
MySQLUbuntu 20.04

I’ve been trying to install MySQL 5.7 on my Ubuntu 20.04 Droplet and I get an error when launching mysql community server and I get stucked there.

These are the steps I followed:

As my current mysql installation has not previews packages I did:

1) Unistall MySQL

service mysql stop

sudo apt-get remove --purge mysql* 

sudo apt-get purge mysql*

sudo apt autoremove && sudo apt autoclean

sudo apt-get remove dbconfig-mysql

2) Download package

sudo apt-get dist-upgrade

cd /tmp

curl -OL

sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

3) Select my desired version and Enable Previews Packages

4) Start Installation

sudo apt-get update

sudo apt-cache policy mysql-server

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

And then something fails and it cannot start the server:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libmecab2 libtinfo5 mysql-common mysql-community-client
The following NEW packages will be installed:
  libmecab2 libtinfo5 mysql-client mysql-common mysql-community-client
  mysql-community-server mysql-server
0 upgraded, 7 newly installed, 0 to remove and 1 not upgraded.
Need to get 51.2 MB of archives.
After this operation, 315 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 focal/main amd64 mysql-common all 5.8+1.0.5ubuntu2 [7496 B]
Get:2 focal/universe amd64 libtinfo5 amd64 6.2-0ubuntu2 [83.0 kB]
Get:3 focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB]
Get:4 bionic/mysql-5.7 amd64 mysql-community-client amd64 5.7.32-1ubuntu18.04 [14.4 MB]
Get:5 bionic/mysql-5.7 amd64 mysql-client amd64 5.7.32-1ubuntu18.04 [67.2 kB]
Get:6 bionic/mysql-5.7 amd64 mysql-community-server amd64 5.7.32-1ubuntu18.04 [36.4 MB]
Get:7 bionic/mysql-5.7 amd64 mysql-server amd64 5.7.32-1ubuntu18.04 [67.2 kB]
Fetched 51.2 MB in 5s (10.5 MB/s)
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 120955 files and directories currently installed.)
Preparing to unpack .../0-mysql-common_5.8+1.0.5ubuntu2_all.deb ...
Unpacking mysql-common (5.8+1.0.5ubuntu2) ...
Selecting previously unselected package libtinfo5:amd64.
Preparing to unpack .../1-libtinfo5_6.2-0ubuntu2_amd64.deb ...
Unpacking libtinfo5:amd64 (6.2-0ubuntu2) ...
Selecting previously unselected package mysql-community-client.
Preparing to unpack .../2-mysql-community-client_5.7.32-1ubuntu18.04_amd64.deb ...
Unpacking mysql-community-client (5.7.32-1ubuntu18.04) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../3-mysql-client_5.7.32-1ubuntu18.04_amd64.deb ...
Unpacking mysql-client (5.7.32-1ubuntu18.04) ...
Selecting previously unselected package libmecab2:amd64.
Preparing to unpack .../4-libmecab2_0.996-10build1_amd64.deb ...
Unpacking libmecab2:amd64 (0.996-10build1) ...
Selecting previously unselected package mysql-community-server.
Preparing to unpack .../5-mysql-community-server_5.7.32-1ubuntu18.04_amd64.deb ...
Unpacking mysql-community-server (5.7.32-1ubuntu18.04) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../6-mysql-server_5.7.32-1ubuntu18.04_amd64.deb ...
Unpacking mysql-server (5.7.32-1ubuntu18.04) ...
Setting up libmecab2:amd64 (0.996-10build1) ...
Setting up mysql-common (5.8+1.0.5ubuntu2) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up libtinfo5:amd64 (6.2-0ubuntu2) ...
Setting up mysql-community-client (5.7.32-1ubuntu18.04) ...
Setting up mysql-client (5.7.32-1ubuntu18.04) ...
Setting up mysql-community-server (5.7.32-1ubuntu18.04) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Created symlink /etc/systemd/system/ → /lib/systemd/system/mysql.service.
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Wed 2020-11-25 06:24:48 -05; 8ms ago
    Process: 15083 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
    Process: 15132 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/ (code=exited, status=1/FAILURE)

Nov 25 06:24:48 FoxyWD-VPS-2 systemd[1]: mysql.service: Control process exited, code=exited, status=1/FAILURE
Nov 25 06:24:48 FoxyWD-VPS-2 systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 25 06:24:48 FoxyWD-VPS-2 systemd[1]: Failed to start MySQL Community Server.
Nov 25 06:24:48 FoxyWD-VPS-2 systemd[1]: mysql.service: Scheduled restart job, restart counter is at 1.
Nov 25 06:24:48 FoxyWD-VPS-2 systemd[1]: Stopped MySQL Community Server.
Nov 25 06:24:48 FoxyWD-VPS-2 systemd[1]: Starting MySQL Community Server...
dpkg: error processing package mysql-community-server (--configure):
 installed mysql-community-server package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-community-server (= 5.7.32-1ubuntu18.04); however:
  Package mysql-community-server is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Processing triggers for systemd (245.4-4ubuntu3.3) ...
No apport report written because the error message indicates its a followup error from a previous failure.
                          Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.1) ...
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

Any help on how to downgrade my mysql?


Carlos C.

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

Hi @foxywd,

Before you begin, I urge you to do a snapshot of your droplet just in ace.

First, you need to uninstall anything that is related to MySQL:

sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean

Then the important bit, this error could be caused because your distribution is not upgraded recently, or at least conflicts are not resolved properly. So next thing is to upgrade it like this:

sudo apt-get dist-upgrade

Now after this is done, you can try to install mysql as normal again.

Another solution would be to see if any leftovers are there

sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql*

Once you remove them you should be able to install MySQL. Please note that removing these folders will mean losing your old configuration files.


For anyone who now attempts to use this article (for Ubuntu 20.04) you need to change the version from 5.7.32 to instead be 5.7.33

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

Combining all of the great advice in this thread:

Clear out MySQL 8:

sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get dist-upgrade
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql*

Install MySQL 5.7.35:

sudo dpkg -i mysql-apt-config_0.8.14-1_all.deb

When prompted select Ubuntu Bionic. Then select the first option to change MySQL8 to MySql 5.7. Then select “OK”.

sudo apt-get update
sudo apt-cache policy mysql-server
sudo apt install -f mysql-client=5.7.35-1ubuntu18.04 mysql-community-server=5.7.35-1ubuntu18.04 mysql-server=5.7.35-1ubuntu18.04