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

Har*_*rry 29 mysql 16.04

我最近重新安装了 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)
Run Code Online (Sandbox Code Playgroud)

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

$ 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)
Run Code Online (Sandbox Code Playgroud)

这是输出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)
Run Code Online (Sandbox Code Playgroud)

小智 87

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)
Run Code Online (Sandbox Code Playgroud)

它的真正意思是该软件包mysql-server-5.7是 的依赖项mysql-server,已安装,但未配置。因此,您需要使用purge它来删除mysql-server-5.7.

sudo apt purge mysql-server mysql-server-5.7
Run Code Online (Sandbox Code Playgroud)

基本原理

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

当您删除某些包时,它可能无法处理这些相同的依赖项。在这篇文章的情况下,该依赖项是mysql-server-5.7.

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

dpkg-query -l [package-name-here]
Run Code Online (Sandbox Code Playgroud)

通常,如果您看到代码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)
Run Code Online (Sandbox Code Playgroud)

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

当你告诉aptremove的东西,它可以离开包,配置文件和其他项目,可以在自动安装问题。

当你告诉aptpurge东西它也最好去除任何面包屑remove可能会留下。

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

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

1) 调查mysql服务

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

sudo systemctl status [pattern]
Run Code Online (Sandbox Code Playgroud)

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

systemctl status mysql.service
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

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

2)停止mysql服务使用systemctl

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

sudo systemctl stop [pattern]
Run Code Online (Sandbox Code Playgroud)

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

sudo systemctl kill [pattern]
Run Code Online (Sandbox Code Playgroud)

例如

sudo systemctl stop mysql
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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

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

确保apt update首先然后apt install

sudo apt update    
sudo apt install mysql-server mysql-client --fix-broken --fix-missing
Run Code Online (Sandbox Code Playgroud)

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

如果上述方法均无效,则您必须手动下载源代码、编译并使用 make 或 bash 从那里安装(不像听起来那么痛苦,因为它都是自动化的)。

  • 注意:`sudo rm -rf /var/lib/mysql` 将删除默认位置的所有数据库。先备份! (5认同)

小智 7

第一篇文章的问题是你不能很好地重新配置一个元包,而不是为 sql 项目。您需要指定当前发布的项目。

说使用;

apt search mysql-server
Run Code Online (Sandbox Code Playgroud)

那应该显示一个包列表

"mysql-server-5.7" "mysql-server-core-5.7" 或更高版本

然后;

dpkg-reconfigure --force mysql-server-5.7 mysql-server-core-5.7
Run Code Online (Sandbox Code Playgroud)

完毕。


Ali*_*our -2

尝试apt-get -f install修复损坏的 SQL 包,如果包管理器仍然存在问题,请下载 SQL Server 源代码并编译它!但是尝试上面的命令并使用dpkg -l | grep sql来找出包管理器是否仍然认为你是 SQL ..