How to forcefully remove MySQL and MariaDB with unmet dependencies, when apt-get and dpkg do not helped?

5,965

God exists! :D

The problem was solved by entering:

sudo apt-get -f install

without any other parameters

and later displaying all packages via:

sudo dpkg -l | grep mariadb
sudo dpkg -l | grep mysql

and removing problematic packages in the right order:

sudo apt-get --purge autoremove package_name

After the complete removal of all problematic packages, I could re-install MySQL without any problems...

Thank you @MarkWagner for your help.

Share:
5,965

Related videos on Youtube

simhumileco
Author by

simhumileco

I'm a full-stack web application developer. I like to deliver top-quality software and learn new things every day.

Updated on September 18, 2022

Comments

  • simhumileco
    simhumileco almost 2 years

    I had installed mysql-server on my Ubuntu 16.04 LTS and it worked very good...

    Next I installed mariadb-server and mariadb-client. There ware some connections with MySQL so I decided to forcefully uninstall all MariaDB components. After that I had problems with MySQL. So I decide to forcefully reinstall MySQL...

    I could not uninstalled mysql-server because there are unmet dependencies after uninstalling MariaDB...

    So I tried all possible combinations with apt-get and dpkg to forcefully remove the remains of MySQL and MariaDB... Finally, unfortunately I also manually deleted all files in the directory tree, which contained anything in the name from MySQL or MariaDB...

    $ sudo dpkg --audit
    The following packages have been unpacked but not yet configured.
    They must be configured using dpkg --configure or the configure
    menu option in dselect for them to work:
     mysql-server         MySQL Server meta package depending on latest version
    
    The following packages are missing the list control file in the
    database, they need to be reinstalled:
     mariadb-client       MariaDB database client (metapackage depending on the lat
     mariadb-server-10.0  MariaDB database server binaries
     mariadb-server-core-10.0 MariaDB database core server files
    
    The following packages are missing the md5sums control file in the
    database, they need to be reinstalled:
     mariadb-client       MariaDB database client (metapackage depending on the lat
     mariadb-server-10.0  MariaDB database server binaries
     mariadb-server-core-10.0 MariaDB database core server files
    

    But I still can not re-install MySQL because the dependencies associated with MariaDB are missing and vice versa...

    $ sudo apt-get install mysql-server
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    mysql-server is already the newest version (5.7.22-1ubuntu16.04).
    You might want to run 'apt-get -f install' to correct these:
    The following packages have unmet dependencies:
     mariadb-client : Depends: mariadb-client-10.0 (>= 10.0.34-0ubuntu0.16.04.1) but it is not going to be installed
     mariadb-server-10.0 : PreDepends: mariadb-common (>= 10.0.34-0ubuntu0.16.04.1) but it is not going to be installed
                           Depends: mariadb-client-10.0 (>= 10.0.34-0ubuntu0.16.04.1) but it is not going to be installed
                           Breaks: mysql-server
     mariadb-server-core-10.0 : Depends: mariadb-common (>= 10.0.34-0ubuntu0.16.04.1) but it is not going to be installed
     mysql-server : Depends: mysql-community-server (= 5.7.22-1ubuntu16.04) but it is not going to be installed
    E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
    
    
    $ sudo dpkg --configure mysql-server
    dpkg: dependency problems prevent configuration of mysql-server:
     mysql-server depends on mysql-community-server (= 5.7.22-1ubuntu16.04); however:
      Package mysql-community-server is not installed.
     mariadb-server-10.0 (10.0.34-0ubuntu0.16.04.1) breaks mysql-server and is installed.
    
    dpkg: error processing package mysql-server (--configure):
     dependency problems - leaving unconfigured
    Errors were encountered while processing:
     mysql-server
    

    And another listings:

    $ sudo dpkg --list | grep -i mysql
    ii  dbconfig-mysql                             2.0.4ubuntu1                                             all          dbconfig-common MySQL/MariaDB support
    ii  libdbd-mysql-perl                          4.033-1ubuntu0.1                                         amd64        Perl5 database interface to the MySQL database
    ii  libmysqlclient20:amd64                     5.7.22-0ubuntu0.16.04.1                                  amd64        MySQL database client library
    ii  mysql-apt-config                           0.8.9-1                                                  all          Auto configuration for MySQL APT Repo.
    ii  mysql-common                               5.7.22-0ubuntu0.16.04.1                                  all          MySQL database common files, e.g. /etc/mysql/my.cnf
    iU  mysql-server                               5.7.22-1ubuntu16.04                                      amd64        MySQL Server meta package depending on latest version
    rc  mysql-server-5.7                           5.7.22-0ubuntu0.16.04.1                                  amd64        MySQL database server binaries and system database setup
    ii  php-mysql                                  1:7.2+60+ubuntu16.04.1+deb.sury.org+1                    all          MySQL module for PHP [default]
    ii  php5.6-mysql                               5.6.35-1+ubuntu16.04.1+deb.sury.org+1                    amd64        MySQL module for PHP
    ii  php7.2-mysql                               7.2.5-1+ubuntu16.04.1+deb.sury.org+1                     amd64        MySQL module for PHP
    ii  phpmyadmin                                 4:4.5.4.1-2ubuntu2                                       all          MySQL web administration tool
    ii  python-pymysql                             0.7.2-1ubuntu1                                           all          Pure-Python MySQL driver - Python 2.x
    
    
    $ sudo dpkg --list | grep -i mariadb
    ii  dbconfig-mysql                             2.0.4ubuntu1                                             all          dbconfig-common MySQL/MariaDB support
    ii  mariadb-client                             10.0.34-0ubuntu0.16.04.1                                 all          MariaDB database client (metapackage depending on the latest version)
    ii  mariadb-server-10.0                        10.0.34-0ubuntu0.16.04.1                                 amd64        MariaDB database server binaries
    ii  mariadb-server-core-10.0                   10.0.34-0ubuntu0.16.04.1                                 amd64        MariaDB database core server files
    
    
    $ sudo dpkg -i | grep mysql
    dpkg: error: --install needs at least one package archive file argument
    
    
    $ sudo dpkg -i | grep mariadb
    dpkg: error: --install needs at least one package archive file argument
    

    Actually I need to have MySQL on my system, but I can't reinstall the Ubuntu.

    I know that I made a lot of problems on my own, but maybe someone smarter than me can advise something that can be useful to me.

    I believe that solving this problem can help many people in a similar situation which can also happen with other services.

    • Admin
      Admin about 6 years
      Looks like you need to uninstall mariadb-server-10.0. Also sudo dpkg -i | grep mariadb should have been sudo dpkg -l | grep mariadb