清除后无法重新安装 mysql-server

清除后无法重新安装 mysql-server

我最近全新安装了 Ubuntu 16.04。我还通过 安装了mysql-servermysql-client(其默认版本 5.7.12)apt-get install

由于 5.7.12 出现了一些问题,我决定卸载它。我先尝试了一下,但发现像和apt-get remove mysql-server mysql-client这样的工件没有被删除。/etc/mysql/var/lib/mysql

然后我尝试了一下apt-get --purge removed mysql-server mysql-client,但仍然没有区别。

因此,我手动删除了它们(通过rm -rf)。我还手动删除了来自任何依赖包(如)的所有*mysql*文件。/usr/mysql-*mysql-common

然而,现在,当我想重新安装时mysql-server and -client,发现我无法重新安装。

事实上,我现在处于一种既不能apt-get remove mysql-server也不能的状态apt-get install mysql-server

我该如何解决这种情况?如果我的本地软件包存储库元数据已损坏,我该如何修复它?

我讨厌仅仅因为 而再次重新安装整个操作系统以及我所有的其他应用程序和环境mysql-server

例如,以下是我尝试删除时收到的错误mysql-server

$ apt-get remove  mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libaio1 mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  mysql-server
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 159 kB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 237601 files and directories currently installed.)
Removing mysql-server (5.7.12-0ubuntu1) ...
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 mysql-server-5.7
E: Sub-process /usr/bin/dpkg returned an error code (1)

当我尝试安装时,出现此错误:

$ apt-get -f install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
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/10.1 kB of archives.
After this operation, 159 kB of additional disk space will be used.
Selecting previously unselected package mysql-server.
(Reading database ... 237599 files and directories currently installed.)
Preparing to unpack .../mysql-server_5.7.12-0ubuntu1_all.deb ...
Unpacking mysql-server (5.7.12-0ubuntu1) ...
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 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-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

以下是 的输出apt-get install -f

$ apt-get 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.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 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-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

编辑于 2017 年 1 月 10 日:这是对此帖子的一次重大审查,以纠正此帖子中的严重问题。

内心的错误

问题是该软件包仍然处于半安装和半配置状态,需要明确删除。

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-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

它实际上说的是,该软件包mysql-server-5.7是 的依赖项mysql-server,已安装,但尚未配置。因此您需要purge它来删除 留下的那些痕迹mysql-server-5.7

sudo apt purge mysql-server mysql-server-5.7

基本原理

当您使用 安装软件时apt,它也会自动为您处理依赖关系。

当您删除某些包时,它可能无法处理相同的依赖项。就本文而言,该依赖项是mysql-server-5.7

您可以通过发出以下命令来检查包状态。

dpkg-query -l [package-name-here]

通常,如果您看到代码unrc包名称左侧的代码,您就能判断它是否真的是一个损坏的包。

当我遇到此问题时,它与libapache2-mod-php和有关libapache2-mod-php7.0。这是我的输出。

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                        Version            Architecture       Description
+++-===========================-==================-==================-============================================================
un  libapache2-mod-php          <none>             <none>             (no description available)

就我而言,它声称我的包的状态未知,并且它没有安装(代码un)在我的系统上。

当您告诉apt某事时remove,它可能会留下包、配置文件和其他在自动安装期间可能会出现问题的项目。

当你告诉aptpurge要做什么时,最好删除remove可能遗留的任何面包屑。

我最初声明我假设该进程仍在运行,但很可能它处于非活动状态,或者已停止运行。

检查该服务是否干扰您删除包裹的最佳方法是先检查该服务。

1)调查mysql服务

使用提供给我们的系统错误apt,我们实际上可以通过检查服务systemctl状态来调查错误mysql

sudo systemctl status [pattern]

在我们的例子中,我们想看看 mysql 是否正在运行,因此可以输入

systemctl status mysql.service

如果服务正在运行,您应该会看到此输出

systemctl status mysql
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-01-10 23:10:06 EST; 1h 3min ago
 Main PID: 1206 (mysqld)
   CGroup: /system.slice/mysql.service
           └─1206 /usr/sbin/mysqld

注意:如果该服务已停止,您将看到一条简短消息,表明没有该名称的服务正在运行,然后跳至步骤 3。

2)mysql使用以下方法停止服务systemctl

service注意: [pattern] 必须是或列出的名称initctl。我使用的原因pattern是因为systemctl使用正则表达式匹配,所以如果必须使用参数,请小心kill

sudo systemctl stop [pattern]

其中pattern代表 mysql 守护进程/服务名称。如果停止不起作用,请尝试

sudo systemctl kill [pattern]

例如

sudo systemctl stop mysql

3)卸载/清除mysql

如果您需要完全清除,请确保先停止服务或进程,然后确保删除正确的文件和目录!

注意:请确保您针对的是正确的mysql版本。例如,如果您使用 5.5,请适当调整版本号。

警告:以下步骤将删除您的数据!(必须执行第一个命令来进行备份)

来源:如何卸载 MySQL?

tar -zcvf ~/msql_backup.tar.gz /etc/mysql /var/lib/mysql 
sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-5.7 mysql-client-core-5.7
sudo rm -rfv /etc/mysql /var/lib/mysql
sudo apt autoremove
sudo apt autoclean

4)修复损坏的软件包并处理缺失的依赖项

如果上述步骤对您不起作用,您可能需要运行apt选项--fix-broken来修复任何造成的损害。

确保apt update首先然后apt install

sudo apt update    
sudo apt install mysql-server mysql-client --fix-broken --fix-missing

5)当其他方法都失败时,mysql自己构建和安装

如果以上方法都不起作用,您将必须手动下载源代码,编译并使用 make 或 bash 从那里进行安装(由于它是全部自动化的,所以并不像听起来那么痛苦)。

答案2

第一篇文章的问题在于您无法重新配置元包,尤其是 sql 项。您需要指定当前发布的项。

说用;

apt search mysql-server

这将显示一个软件包列表,即

“mysql-server-5.7” “mysql-server-core-5.7” 或更高版本

然后;

dpkg-reconfigure --force mysql-server-5.7 mysql-server-core-5.7

完毕。

答案3

这是适合您的正确解决方案

首先,您必须删除所有 mysql-server 包:

警告:以下步骤将删除您的数据!请先备份!

sudo rm -rf /var/lib/mysql

然后安装:

sudo apt-get install lamp-server^

或者你可以这样做:

sudo apt-get install mysql-server

答案4

从 MySQL 切换到 MariaDB 时也发生了此错误(https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1490071)。

MySQL 二进制数据文件与 MariaDB 不兼容,因此我切换回 MySQL,因为我没有时间摆弄 mysqldump。

首先我必须将 MariaDB 数据从 移走/var/lib/mysql,然后安装 MySQL,然后将我的原始数据从/var/lib/mysql-5.7(此备份是在错误发生之前自动创建的)移到/var/lib/mysql

相关内容