无法在 ubuntu 中删除或安装 Mysql

无法在 ubuntu 中删除或安装 Mysql

我尝试删除 mysql-server,但遇到了这个问题

0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 111 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 239230 files and directories currently installed.)
Removing mysql-server (8.0.21-0ubuntu0.20.04.4) ...
Setting up mysql-server-8.0 (8.0.21-0ubuntu0.20.04.4) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-8.0 (--configure):
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2
Errors were encountered while processing:
 mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

当我尝试安装时,遇到了这样的问题

firdausyah22@lenovo110:~$ sudo apt install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfprint-2-tod1
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  mysql-server
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/9.552 B of archives.
After this operation, 111 kB of additional disk space will be used.
Selecting previously unselected package mysql-server.
(Reading database ... 239228 files and directories currently installed.)
Preparing to unpack .../mysql-server_8.0.21-0ubuntu0.20.04.4_all.deb ...
Unpacking mysql-server (8.0.21-0ubuntu0.20.04.4) ...
Setting up mysql-server-8.0 (8.0.21-0ubuntu0.20.04.4) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-8.0 (--configure):
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-8.0; however:
  Package mysql-server-8.0 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-8.0
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

以前我使用 XAMPP。我已删除 XAMPP,因为我将使用 Nginx 作为 Web 服务器,但我的 MYSQL 有问题

如何解决这个问题呢?

答案1

似乎您有一些损坏的依赖项。首先尝试清除与 MySQL 相关的所有内容:

sudo apt purge mysql.*

注意星号前面的句号。这是一个通配符,表示“应用于所有以“mysql”开头的包”。

请注意,Ubuntu 的较新版本的语法略有不同(没有句号):

sudo apt-get purge "mysql*"

清除不仅会删除应用程序,还会删除与其直接相关的所有配置、系统和数据文件,因此应该会给你一个干净的环境。

然后尝试重新安装它:

sudo apt install mysql-server

如果这是 Ubuntu Server,您还可以使用任务选择器来选择要设置 LAMP 服务器或仅 MySQL 服务器:

sudo tasksel

相关内容