清除后无法重新安装mysql-server
作者:互联网
我最近刚刚安装了Ubuntu 16.04.我还通过apt-get install安装了mysql-server和mysql-client(默认版本为5.7.12).
因为5.7.12显示了一些问题,所以我决定将其卸载.我首先尝试了apt-get删除mysql-server mysql-client但是看到像/ etc / mysql和/ var / lib / mysql这样的工件没有被删除.
然后我尝试了apt-get –purge删除了mysql-server mysql-client,但仍然没有区别.
所以,我手动删除它们(通过rm -rf).我还手动删除了来自任何mysql- *依赖包(如mysql-common)的/ usr /下的所有* mysql *文件.
但是,现在,当我想重新安装mysql-server和-client时,我发现我不能.
事实上,现在我处于一种状态,我既不能删除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日编辑:这是对这篇文章的重要评论,以纠正这篇文章中的严重问题.
心中的错误
问题是程序包仍处于半安装和半配置状态的系统上,需要明确删除.
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的依赖,已经安装,但是没有配置.所以你需要清除它以删除mysql-server-5.7留下的那些面包屑.
sudo apt purge mysql-server mysql-server-5.7
合理
使用apt安装软件时,它也会自动处理依赖项.
删除某些包时,它可能无法处理这些相同的依赖项.在这篇文章的例子中,该依赖是mysql-server-5.7.
您可以通过发出以下命令来检查包状态.
dpkg-query -l [package-name-here]
通常,如果您看到包名称左侧的代码un或rc,您将能够判断它是否确实是一个损坏的包.
当我遇到这个问题时,它是使用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删除某些内容时,它可能会留下自动安装过程中可能存在问题的包,配置文件和其他项目.
当你告诉apt清除它所做的事情时,最好删除任何可能留下的删除的面包屑.
我最初表示我认为该过程仍在运行,但很可能是非活动或死亡.
检查服务是否干扰您的程序包删除的最佳方法是首先检查该服务.
1)调查mysql服务
使用apt给我们的系统错误,我们实际上可以通过检查mysql服务的状态来使用systemctl来调查错误
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]必须是service或initctl列出的名称.我使用模式的原因是因为systemctl使用正则表达式匹配,所以如果必须使用kill参数,请小心.
sudo systemctl stop [pattern]
其中pattern表示mysql守护程序/服务名称.如果停止不起作用尝试
sudo systemctl kill [pattern]
例如
sudo systemctl stop mysql
3)卸载/清除mysql
如果您需要完全清除,请确保先停止服务或进程,然后确保删除正确的文件和目录!
注意:确保您的目标是正确的mysql版本.例如,如果使用5.5,请相应地调整版本号.
警告:以下步骤将删除您的数据! (必须执行第一个命令才能进行备份)
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然后再安装
sudo apt update
sudo apt install mysql-server mysql-client --fix-broken --fix-missing
5)当所有其他方法都失败时,自己构建并安装mysql
如果上述方法都不起作用,您将不得不手动下载源代码,编译并使用make或bash从那里进行安装(不像听起来那么痛苦,因为它全部自动化).
标签:mysql,16-04 来源: https://codeday.me/bug/20190807/1611632.html