Ubuntu 20.10 无法安装或卸载 MySQL

Don*_*onP 2 upgrade updates mysql

在升级到 21.04 LTS 之前尝试更新我的系统时,MySQL 给出了无法更新或修复的错误,因此我使用以下命令清除了它:

sudo apt purge mysql-server-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  mysql-server-8.0*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 555934 files and directories currently installed.)
Purging configuration files for mysql-server-8.0 (8.0.17-0ubuntu2) ...
Processing triggers for systemd (246.6-1ubuntu1.3) ...
Run Code Online (Sandbox Code Playgroud)

但是,现在它不会重新安装。

sudo apt-get install mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-common : Conflicts: mysql-client-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
                Conflicts: mysql-client-core-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
Run Code Online (Sandbox Code Playgroud)

有些东西显然坏了,但不确定是什么,那么我该如何继续?

以下是基于评论的一些附加输出:

Sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu groovy InRelease
Hit:2 http://archive.ubuntu.com/ubuntu groovy-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu groovy-security InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
sudo apt clean

sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo apt update && sudo apt upgrade
Hit:1 http://archive.ubuntu.com/ubuntu groovy InRelease
Hit:2 http://archive.ubuntu.com/ubuntu groovy-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu groovy-security InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo dpkg --configure -a

sudo apt install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Run Code Online (Sandbox Code Playgroud)

然后尝试安装 mysql-client,尽管未安装,但在 mysql-client 上出现错误:

sudo apt install mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-common : Conflicts: mysql-client-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
                Conflicts: mysql-client-core-8.0 but 

8.0.25-0ubuntu0.20.10.1 is to be installed

E: Unable to correct problems, you have held broken packages.
Run Code Online (Sandbox Code Playgroud)

额外的尝试:

sudo apt install mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-common : Conflicts: mysql-client-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
                Conflicts: mysql-client-core-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
E: Unable to correct problems, you have held broken packages.

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

sudo apt purge mysql-client-core-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-client-core-8.0' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Run Code Online (Sandbox Code Playgroud)

它似乎告诉我MySQL没有安装,但是安装它有冲突!我该如何解决这个难题?

mat*_*igo 6

apt有时可以通过稍微清洁来解决这个问题。在终端中,尝试以下操作:

\n
sudo apt update\nsudo apt clean\nsudo apt autoremove\n
Run Code Online (Sandbox Code Playgroud)\n

现在尝试安装 MySQL 客户端。如果错误仍然存​​在,那么您可能需要“修复”安装:

\n
sudo apt --fix-broken install\nsudo apt update && sudo apt upgrade\nsudo dpkg --configure -a\nsudo apt install -f\n
Run Code Online (Sandbox Code Playgroud)\n

现在您应该能够安装客户端:

\n
sudo apt install mysql-client\n
Run Code Online (Sandbox Code Playgroud)\n

注意:尽管您已经删除了 MySQL Server,但/var/lib/mysql. 这些是在卸载后故意留下的。如果您不需要任何以前可用的数据库,请随意删除此目录。您可能还会/etc/mysql留下来,如果您不再需要配置文件,也可以将其删除。

\n
\n

从 Ubuntu(18.04 及更高版本)清理 MySQL

\n

如果 MySQL 无法正常运行,那么您可能需要按照以下步骤将其从系统中彻底清除:

\n
    \n
  1. 打开终端(如果尚未打开)
  2. \n
  3. 确保 MySQL 进程已停止(即使它没有运行):\n
    sudo systemctl stop mysqld\n
    Run Code Online (Sandbox Code Playgroud)\n
  4. \n
  5. 从系统中清理 MySQL 软件包:\n
    sudo apt purge mysql-server mysql-common mysql-server-core-* mysql-client-core-*\n
    Run Code Online (Sandbox Code Playgroud)\n并且,为了完整起见,让我们确保系统上没有安装 MariaDB:\n
    sudo apt purge mariadb-server \n
    Run Code Online (Sandbox Code Playgroud)\n
  6. \n
  7. 检查是否有任何剩余的包:\n
    sudo dpkg -l | grep mysql\n
    Run Code Online (Sandbox Code Playgroud)\n理想情况下你会得到零结果。但是,如果仍然安装了任何东西,您可能会看到类似这样的内容:\n
    ii  libmysqlclient21:amd64                     8.0.25-0ubuntu0.20.04.1                    amd64        MySQL database client library\nii  php-mysql                                  2:7.4+75                                   all          MySQL module for PHP [default]\nii  php7.4-mysql                               7.4.3-4ubuntu2.4                           amd64        MySQL module for PHP\n
    Run Code Online (Sandbox Code Playgroud)\n如果您确实看到了值,apt purge则它们已脱离系统:\n
    sudo apt purge php-mysql php7.4-mysql libmysqlclient21\n
    Run Code Online (Sandbox Code Playgroud)\n对 MariaDB 执行相同操作:\n
    sudo dpkg -l | grep mariadb\n
    Run Code Online (Sandbox Code Playgroud)\n
  8. \n
  9. 清理 MySQL 目录的文件系统(MariaDB 也使用该目录):\n
    sudo rm -rf /var/lib/mysql/\nsudo rm -rf /etc/mysql/\nsudo rm -rf /var/log/mysql\n
    Run Code Online (Sandbox Code Playgroud)\n仔细检查并清理这些文件:\n
    sudo find / -iname \'mysql*\' -exec rm -rf {} \\;\n
    Run Code Online (Sandbox Code Playgroud)\n重要提示:此命令将从mysql您的系统中删除任何以 开头的文件,而不要求确认。请务必非常小心和谨慎地使用它。
  10. \n
  11. 删除 MySQL 用户帐户和组:\n
    sudo deluser --remove-home mysql\nsudo delgroup mysql\n
    Run Code Online (Sandbox Code Playgroud)\n如果无法删除该组,请检查是否有其他用户帐户属于该 MySQL 组:\n
    less /etc/passwd\n
    Run Code Online (Sandbox Code Playgroud)\n如果找到,请从组中删除用户,然后delgroup再次删除。
  12. \n
  13. 删除可能用于安装特定版本 MySQL 的任何第三方 PPA
  14. \n
  15. 更新您的源列表:\n
    sudo apt autoremove -y\nsudo apt autoclean\n
    Run Code Online (Sandbox Code Playgroud)\n
  16. \n
  17. 喝杯咖啡,因为是时候休息一下了 \xe2\x98\x95\xef\xb8\x8f
  18. \n
\n

只要您的计算机上没有配置某种 XAMPP 系统,就应该完全消除计算机上的数据库引擎。

\n