Mysql-common cannot be uninstalled

7,072

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
Share:
7,072

Related videos on Youtube

Azeirah
Author by

Azeirah

Second year computer engineering student. Developer of SMG music display, helping streamers connect with their audiences through their music. https://smgmusicdisplay.com

Updated on September 18, 2022

Comments

  • Azeirah
    Azeirah over 1 year

    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?

    • Jos
      Jos about 8 years
      Try installing it, then removing it.
    • Azeirah
      Azeirah about 8 years
      @jos This actually worked perfectly, post it as an answer and I'll accept it!