![apt-get 不断尝试安装已安装的软件包](https://linux22.com/image/110947/apt-get%20%E4%B8%8D%E6%96%AD%E5%B0%9D%E8%AF%95%E5%AE%89%E8%A3%85%E5%B7%B2%E5%AE%89%E8%A3%85%E7%9A%84%E8%BD%AF%E4%BB%B6%E5%8C%85.png)
我在 Windows 上使用 Bash,但在某些时候让 MySQL 工作时遇到了一些麻烦。
现在它工作正常,但是看起来 apt-get 中存在一些安装过程的残余。每次我尝试安装任何软件包(无论是否与 mysql 相关),它都会运行mysql_upgrade
并失败。
然而它不需要运行这个,因为 MySQL 工作得很好。有什么方法可以让 apt-get 停止这样做吗?
有关信息,它的外观如下:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
snap-confine
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libzip4
The following NEW packages will be installed:
libzip4 php7.1-zip
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
Need to get 59.8 kB of archives.
After this operation, 191 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://ppa.launchpad.net/ondrej/php/ubuntu xenial/main amd64 libzip4 amd64 1.1.2-1.1+deb.sury.org~xenial+1 [40.1 kB]
Get:2 http://ppa.launchpad.net/ondrej/php/ubuntu xenial/main amd64 php7.1-zip amd64 7.1.4-1+deb.sury.org~xenial+1 [19.8 kB]
Fetched 59.8 kB in 0s (260 kB/s)
Selecting previously unselected package libzip4:amd64.
(Reading database ... 57661 files and directories currently installed.)
Preparing to unpack .../libzip4_1.1.2-1.1+deb.sury.org~xenial+1_amd64.deb ...
Unpacking libzip4:amd64 (1.1.2-1.1+deb.sury.org~xenial+1) ...............................................................................................................................................................................]
Selecting previously unselected package php7.1-zip.#####.................................................................................................................................................................................]
Preparing to unpack .../php7.1-zip_7.1.4-1+deb.sury.org~xenial+1_amd64.deb ...
Unpacking php7.1-zip (7.1.4-1+deb.sury.org~xenial+1) ...#############....................................................................................................................................................................]
Processing triggers for libc-bin (2.23-0ubuntu7) ...##########################################...........................................................................................................................................]
Processing triggers for libapache2-mod-php7.1 (7.1.4-1+deb.sury.org~xenial+1) ...
Setting up mysql-server-5.7 (5.7.18-0ubuntu0.16.04.1) ...
invoke-rc.d: could not determine current runlevel
* Stopping MySQL database server mysqld [ OK ]invoke-rc.d: could not determine current runlevel
invoke-rc.d: could not determine current runlevel
* Stopping MySQL database server mysqld [ OK ]invoke-rc.d: could not determine current runlevel
mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
mysql_upgrade failed with exit status 11
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
Setting up libzip4:amd64 (1.1.2-1.1+deb.sury.org~xenial+1) ...
No apport report written because the error message indicates its a followup error from a previous failure.
Progress: [ 47%] [########################################################################################Setting up php7.1-zip (7.1.4-1+deb.sury.org~xenial+1) .........................................................................]
Progress: [ 52%] [##################################################################################################################.....................................................................................................]
Creating config file /etc/php/7.1/mods-available/zip.ini with new version
Processing triggers for libc-bin (2.23-0ubuntu7) ...#############################################################################################........................................................................................]
Processing triggers for libapache2-mod-php7.1 (7.1.4-1+deb.sury.org~xenial+1) ...
Errors were encountered while processing:
mysql-server-5.7
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
答案1
该mysql-server-5.7
软件包未正确安装。文件已解压,但在完成安装包时出现问题。出了什么问题不会影响你——你知道这一点——但包管理器无法知道这一点。
阻止安装完成的错误是
mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) while connecting to the MySQL server
我对MySQL不熟悉,所以我不知道如何解决这个问题。这是一个非常普遍的错误,可能有多种原因。您可能有一个不寻常的 MySQL 配置,Debian 的脚本无法处理。
此时正在运行但失败的脚本是/var/lib/dpkg/info/mysql-server-5.7.postinst
。如果您想调试失败的原因,请将行更改set -e
为set -ex
脚本的开头,您将获得该脚本执行的命令的跟踪信息。
要尝试再次运行升级,请运行
sudo dpkg --configure -a
或者
sudo apt-get -f install
/var/lib/dpkg/info/mysql-server-5.7.postinst
当成功运行时(即退出状态为 0),包管理器将感到满意。您可能会想在不完成其工作的情况下强制它以成功状态退出,但要小心:如果搞砸了,可能会损坏您的数据库。