3

I'm trying to completely uninstall mysql to reinstall it later, after uninstalling all mysql-related packages, mysql-common seems to remain in a broken state.

$ sudo dpkg -l | grep mysql
pc  mysql-common                                  5.6.28-0ubuntu0.15.10.1                      all          MySQL database common files, e.g. /etc/mysql/my.cnf

But running apt-get remove

$ sudo apt-get remove mysql-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-common' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 36 not upgraded.

Or with --purge

$ sudo apt-get remove --purge mysql-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  mysql-common*
0 upgraded, 0 newly installed, 1 to remove and 36 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 199090 files and directories currently installed.)
Removing mysql-common (5.6.28-0ubuntu0.15.10.1) ...
Purging configuration files for mysql-common (5.6.28-0ubuntu0.15.10.1) ...
update-alternatives: error: no alternatives for my.cnf
dpkg: error processing package mysql-common (--purge):
 subprocess installed post-removal script returned error exit status 2
Errors were encountered while processing:
 mysql-common
E: Sub-process /usr/bin/dpkg returned an error code (1)

Additionally, I've removed all mysql related directories and files.

How can I get rid of this lingering broken package?

  • 2
    Try installing it, then removing it. – Jos Apr 22 '16 at 11:32
  • @jos This actually worked perfectly, post it as an answer and I'll accept it! – Azeirah Apr 22 '16 at 19:01
4

Some packages can't be uninstalled if some dependencies are gone, or some configuration files have been deleted for some reason. You will end up with a package that is not completely installed nor completely uninstalled.

The solution, in this case, is to sudo apt-get install the package. If necessary, do sudo apt-get install --reinstall [package]. Missing files will be added to the system, and any missing dependencies installed on the fly. Then the package can be uninstalled completely in the usual way: sudo apt-get remove [package].

If apt-get refuses to re-install the package because of other (dependency) issues, you can only use apt-get to download the package and use dpkg directly to install it:

apt-get download mysql-common
sudo dpkg -i mysql-common_*.deb
sudo apt-get install -f

Sometimes you can skip the download because Apt tends to keep an archive of previously downloaded and installed packages in /var/cache/apt/archives/ so you can start directly from the 2nd step:

sudo dpkg -i /var/cache/apt/archives/mysql-common_*.deb

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.