Linux – APT/DPKG is broken – Unable to remove thesql-server-core-5.5

aptdebianlinuxMySQLuninstall

I want to completely remove any packages related to mysql on my server.
But I seems unable to achieve that task. APT seems unable to understand that mysql-server is not installed on the server. Is it possible to manually tell apt that a package is removed?

╭─root@home /etc/apt
╰─➤  apt-get remove mysql-server-core-5.5                                                                              
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
mysql-server-5.5 : Depends: mysql-client-5.5 (>= 5.5.54-0+deb8u1) but it is not going to be installed
                Depends: mysql-server-core-5.5 (>= 5.5.54-0+deb8u1) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a  solution).

I also have tried to perform a "purge"

╭─root@home /etc/apt
╰─➤  apt-get purge mysql-server-core-5.5                                                                             100 ↵
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 mysql-server-5.5 : Depends: mysql-client-5.5 (>= 5.5.54-0+deb8u1) but it is not going to be installed
                    Depends: mysql-server-core-5.5 (>= 5.5.54-0+deb8u1) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

Running a apt-get -f install does not solve any problem

dpkg: error processing package mysql-server-5.5 (--configure):
 subprocess installed post-installation script returned error exit status 6
Processing triggers for libc-bin (2.19-18+deb8u7) ...
Errors were encountered while processing:
 mysql-server-5.5
E: Sub-process /usr/bin/dpkg returned an error code (1)

Running a apt-get install mysql-server-5.5 –reinstall does not with either.

╭─root@home /etc/apt
╰─➤  apt-get install mysql-server-5.5 --reinstall                                                                    100 ↵
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for mysql-server-5.5:amd64

Trying to remove the manually with dpkg –purge –force-all mysql-community-server mysql-server-5.5 mysql-server-core-5.5 is useless

╭─root@home /etc/apt
╰─➤  dpkg --purge --force-all mysql-community-server mysql-server-5.5 mysql-server-core-5.5                            1 ↵
(Reading database ... 40739 files and directories currently installed.)
Removing mysql-community-server (5.7.17-1debian8) ...
Purging configuration files for mysql-community-server (5.7.17-1debian8) ...
................
dpkg: error processing package mysql-community-server (--purge):
 subprocess installed post-removal script returned error exit status 1
Removing mysql-server-5.5 (5.5.54-0+deb8u1) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: error processing package mysql-server-5.5 (--purge):
 subprocess installed pre-removal script returned error exit status 5
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
Failed to start mysql.service: Unit mysql.service failed to load: No such file or directory.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 6
dpkg: warning: ignoring request to remove mysql-server-core-5.5 which isn't installed
Errors were encountered while processing:
 mysql-community-server
 mysql-server-5.5

Removing the packages one by one does not work either, I am prompted with the "dialog" that want me to set a root password for the mysql-server.

apt-get remove mysql-server
apt-get remove mysql-client
apt-get remove mysql-server-core

I will try my best to update this question as you wish, but I am currently pulling my hair out for this. I am almost about to just reinstall the whole server.

Best Answer

From the message shown, due the dependencies, apt-get stop, this is the correct behaviour. Otherwise modules depends on the package will stop working.

The correct ways is read the message that says about modules that depends on it, then removed them one by one in sequence , until you exhaust all.

From the message, mysql-server-core is needed by mysql-server. So you must do the removal in order.

sudo apt-get purge mysql-server
sudo apt-get purge mysql-client
sudo apt-get purge mysql-common
# I think when you uninstall mysql-server, it will also remove the core

The best way is always use dpkg -l | grep mysql to check related packages installed.

Please try apply answer stated in this question if all the above failed. Nevertheless, some problem is cause by pointing to outdated debian/ubuntu repository that contains old/buggies installation script, but it is rare.