![当 apt-get 和 dpkg 没有帮助时,如何强制删除未满足依赖关系的 MySQL 和 MariaDB?](https://linux22.com/image/722703/%E5%BD%93%20apt-get%20%E5%92%8C%20dpkg%20%E6%B2%A1%E6%9C%89%E5%B8%AE%E5%8A%A9%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E5%BC%BA%E5%88%B6%E5%88%A0%E9%99%A4%E6%9C%AA%E6%BB%A1%E8%B6%B3%E4%BE%9D%E8%B5%96%E5%85%B3%E7%B3%BB%E7%9A%84%20MySQL%20%E5%92%8C%20MariaDB%EF%BC%9F.png)
我已经安装mysql-server
在我的Ubuntu 16.04 LTS而且效果非常好……
接下来我安装了mariadb-server
。mariadb-client
有一些连接MySQL所以我决定强制卸载所有玛拉雅数据库组件。之后我遇到了问题MySQL。所以我决定强制重新安装MySQL...
无法卸载,mysql-server
因为卸载后存在未满足的依赖关系玛拉雅数据库...
所以我尝试了所有可能的组合,apt-get
并dpkg
强行去除MySQL和玛拉雅数据库...最后,不幸的是,我还手动删除了目录树中的所有文件,其中包含名称中的任何内容MySQL或者玛拉雅数据库...
$ 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因为与玛拉雅数据库缺失,反之亦然......
$ 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。
我知道我自己犯了很多问题,但也许比我聪明的人可以给我一些有用的建议。
我相信解决这个问题可以帮助许多处于类似情况的人,这种情况也可能发生在其他服务中。
答案1
上帝存在!: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 的帮助。