Mysql

當 apt-get 和 dpkg 沒有幫助時,如何強制刪除具有未滿足依賴項的 MySQL 和 MariaDB?

  • June 5, 2018

我已經mysql-server在我的Ubuntu 16.04 LTS上安裝了它,它執行得非常好……

接下來我安裝了mariadb-servermariadb-client. 與MySQL有一些聯繫,所以我決定強制解除安裝所有MariaDB組件。之後我遇到了MySQL的問題。所以我決定強行重新安裝MySQL

我無法解除安裝mysql-server,因為解除安裝MariaDB後存在未滿足的依賴項…

所以我嘗試了所有可能的組合apt-getdpkg強制刪除MySQLMariaDB的剩餘部分……最後,不幸的是,我還手動刪除了目錄樹中的所有文件,其中包含MySQLMariaDB名稱中的任何內容……

$ 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

但我仍然無法重新安裝MySQL,因為缺少與MariaDB相關的依賴項,反之亦然……

$ 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

和另一個清單:

$ 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

實際上我需要在我的系統上安裝MySQL,但我無法重新安裝 Ubuntu。

我知道我自己解決了很多問題,但也許比我聰明的人可以提出一些對我有用的建議。

我相信解決這個問題可以幫助許多處於類似情況的人,其他服務也可能發生這種情況。

上帝存在!:D

通過輸入以下內容解決了該問題:

sudo apt-get -f install

沒有任何其他參數

稍後通過以下方式顯示所有包:

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

並以正確的順序刪除有問題的包:

sudo apt-get --purge autoremove package_name

完全刪除所有有問題的軟體包後,我可以重新安裝MySQL沒有任何問題…

感謝@MarkWagner 的幫助。

引用自:https://serverfault.com/questions/915158