我不小心删除了 /etc/mysql(和其他文件),现在每次我尝试安装新包时,apt 都会失败。
然后我尝试用以下方法修复它:
sudo apt --fix-broken install
但它会失败并显示以下错误消息。我的理解是:apt 尝试在执行任何操作之前停止 mysql,但由于文件丢失,因此无法正确停止。如何解决这个问题?
Preconfiguring packages ... (Reading database ... 261168 files and directories currently installed.) Preparing to unpack
.../mysql-server-5.7_5.7.22-0ubuntu0.17.10.1_amd64.deb ...
grep: /etc/mysql/: No such file or directory
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
invoke-rc.d returned 5 There is a MySQL server running, but we failed in our attempts to stop it. Stop it yourself and try again!
dpkg: error processing archive /var/cache/apt/archives/mysql-server-5.7_5.7.22-0ubuntu0.17.10.1_amd64.deb
(--unpack): subprocess new pre-installation script returned error exit status 1
Errors were encountered while processing: /var/cache/apt/archives/mysql-server-5.7_5.7.22-0ubuntu0.17.10.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
答案1
原来是另一个愚蠢的错误,第一个是手动删除mysql配置文件。第二个是我没有删除所有文件,还有2个剩余的软链接
/etc/systemd/系统
指向我删除的 mysql 服务。我猜 apt 会尝试确保 mysql 服务处于非活动状态,当 apt 在
/etc/systemd/系统
apt 会运行它。但是因为它们指向了无效文件,所以操作会失败。我删除它们之后,apt 又可以工作了。我想 systemctl disable 也可以工作,但我没有试过。