当前位置: 首页>>技术教程>>正文


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

,

问题描述

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

因为 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 )。我还手动删除了 /usr/ 下来自任何 mysql-* 依赖包(如 mysql-common )的所有 *mysql* 文件。

但是,现在,当我希望 re-install 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)

最佳办法

2017 年 1 月 10 日编辑:这是对这篇文章的主要评论,以纠正这篇文章中的严重问题。

内心的错误

问题是该包仍在系统上处于 half-installed 和 half-configured 状态,需要明确删除。

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.7mysql-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-phplibapache2-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)。

当您将某些内容告诉 aptremove 时,它可能会留下包、配置文件和其他在自动安装过程中可能出现问题的项目。

当您告诉 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)使用systemctl停止mysql服务

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

sudo systemctl stop [pattern]

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

sudo systemctl kill [pattern]

例如

sudo systemctl stop mysql

3) 卸载/清除 mysql

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

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

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

来源:How do I uninstall 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) 修复损坏的包并处理缺失的依赖项

如果前面的步骤对您不起作用,您可能需要使用 --fix-broken 选项运行 apt 以修复任何损坏。

确保先 apt update 然后 apt install

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

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

如果以上都不起作用,您将不得不手动下载源代码、编译并使用 make 或 bash 从那里安装(不像听起来那么痛苦,因为它都是自动化的)。

次佳办法

第一篇文章的问题是你不能重新配置一个 meta-package 不是为 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

完毕。

第三种办法

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

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

WARNING: the following steps will delete your data! Do a backup first!

sudo rm -rf /var/lib/mysql

然后安装:

sudo apt-get install lamp-server^

或者你可以这样做:

sudo apt-get install mysql-server

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/12319.html,未经允许,请勿转载。